[Transforms] Silence a warning in SROA.cpp (NFC)
[llvm-project.git] / openmp / runtime / test / tasking / kmp_task_modifier_simple_par_old.cpp
blob94e9bbca5fe75da9e4ccff2dd1f5567ae25f4314
1 // RUN: %libomp-cxx-compile-and-run
3 #include <stdio.h>
4 #include <omp.h>
6 #define NT 4
7 #define INIT 10
9 /*
10 The test emulates code generation needed for reduction with task modifier on
11 parallel construct.
13 Note: tasks could just use in_reduction clause, but compiler does not accept
14 this because of bug: it mistakenly requires reduction item to be shared, which
15 is only true for reduction on worksharing and wrong for task reductions.
18 //------------------------------------------------
19 // OpenMP runtime library routines
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 extern void *__kmpc_task_reduction_get_th_data(int gtid, void *tg, void *item);
24 extern void *__kmpc_task_reduction_modifier_init(void *loc, int gtid, int is_ws,
25 int num, void *data);
26 extern void __kmpc_task_reduction_modifier_fini(void *loc, int gtid, int is_ws);
27 extern int __kmpc_global_thread_num(void *);
28 #ifdef __cplusplus
30 #endif
32 //------------------------------------------------
33 // Compiler-generated code
35 typedef struct red_input {
36 void *reduce_shar; /**< shared between tasks item to reduce into */
37 size_t reduce_size; /**< size of data item in bytes */
38 // three compiler-generated routines (init, fini are optional):
39 void *reduce_init; /**< data initialization routine (single parameter) */
40 void *reduce_fini; /**< data finalization routine */
41 void *reduce_comb; /**< data combiner routine */
42 unsigned flags; /**< flags for additional info from compiler */
43 } red_input_t;
45 void i_comb(void *lhs, void *rhs) { *(int *)lhs += *(int *)rhs; }
47 int main() {
48 int var = INIT;
49 omp_set_dynamic(0);
50 omp_set_num_threads(NT);
51 // #pragma omp parallel reduction(task,+:var)
52 #pragma omp parallel reduction(+ : var)
54 int gtid = __kmpc_global_thread_num(NULL);
55 void *tg; // pointer to taskgroup (optional)
56 red_input_t r_var;
57 r_var.reduce_shar = &var;
58 r_var.reduce_size = sizeof(var);
59 r_var.reduce_init = NULL;
60 r_var.reduce_fini = NULL;
61 r_var.reduce_comb = (void *)&i_comb;
62 tg = __kmpc_task_reduction_modifier_init(
63 NULL, // ident_t loc;
64 gtid,
65 0, // 1 - worksharing construct, 0 - parallel
66 1, // number of reduction objects
67 &r_var // related data
69 var++;
70 #pragma omp task /*in_reduction(+:var)*/ shared(var)
72 int gtid = __kmpc_global_thread_num(NULL);
73 int *p_var = (int *)__kmpc_task_reduction_get_th_data(gtid, tg, &var);
74 *p_var += 1;
76 if (omp_get_thread_num() > 0) {
77 #pragma omp task /*in_reduction(+:var)*/ shared(var)
79 int gtid = __kmpc_global_thread_num(NULL);
80 int *p_var = (int *)__kmpc_task_reduction_get_th_data(gtid, tg, &var);
81 *p_var += 1;
84 __kmpc_task_reduction_modifier_fini(NULL, gtid, 0);
86 if (var == INIT + NT * 3 - 1) {
87 printf("passed\n");
88 return 0;
89 } else {
90 printf("failed: var = %d (!= %d)\n", var, INIT + NT * 3 - 1);
91 return 1;