xref: /llvm-project/openmp/runtime/test/ompt/synchronization/reduction/tree_reduce.c (revision 90e4ebdce55fd3c1f8877f19784a5339b9890f98)
13356e268Sprotze@itc.rwth-aachen.de // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s
2*90e4ebdcSprotze@itc.rwth-aachen.de // RUN: %libomp-compile -DNOWAIT && %libomp-run | %sort-threads | FileCheck %s
33356e268Sprotze@itc.rwth-aachen.de // REQUIRES: ompt
43356e268Sprotze@itc.rwth-aachen.de // UNSUPPORTED: gcc
53356e268Sprotze@itc.rwth-aachen.de #include "callback.h"
63356e268Sprotze@itc.rwth-aachen.de #include <omp.h>
73356e268Sprotze@itc.rwth-aachen.de 
83356e268Sprotze@itc.rwth-aachen.de #ifdef NOWAIT
93356e268Sprotze@itc.rwth-aachen.de #define FOR_CLAUSE nowait
103356e268Sprotze@itc.rwth-aachen.de #else
113356e268Sprotze@itc.rwth-aachen.de #define FOR_CLAUSE
123356e268Sprotze@itc.rwth-aachen.de #endif
133356e268Sprotze@itc.rwth-aachen.de 
main()143356e268Sprotze@itc.rwth-aachen.de int main() {
15*90e4ebdcSprotze@itc.rwth-aachen.de   int sum = 0, a = 0, b = 0;
163356e268Sprotze@itc.rwth-aachen.de   int i;
173356e268Sprotze@itc.rwth-aachen.de #pragma omp parallel num_threads(5)
18*90e4ebdcSprotze@itc.rwth-aachen.de // for 32-bit architecture we need at least 3 variables to trigger tree
19*90e4ebdcSprotze@itc.rwth-aachen.de #pragma omp for reduction(+ : sum, a, b) FOR_CLAUSE
203356e268Sprotze@itc.rwth-aachen.de   for (i = 0; i < 10000; i++) {
21*90e4ebdcSprotze@itc.rwth-aachen.de     a = b = sum += i;
223356e268Sprotze@itc.rwth-aachen.de   }
233356e268Sprotze@itc.rwth-aachen.de 
24*90e4ebdcSprotze@itc.rwth-aachen.de 
25*90e4ebdcSprotze@itc.rwth-aachen.de   printf("%i\n", sum);
263356e268Sprotze@itc.rwth-aachen.de   // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
273356e268Sprotze@itc.rwth-aachen.de 
283356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin:
293356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID:[0-9]+]]
303356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin:
313356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID:[0-9]+]]
323356e268Sprotze@itc.rwth-aachen.de 
333356e268Sprotze@itc.rwth-aachen.de   // order and distribution to threads not determined
343356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_begin:
353356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
363356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_end:
373356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
383356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_begin:
393356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
403356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_end:
413356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
423356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_begin:
433356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
443356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_end:
453356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
463356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_begin:
473356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
483356e268Sprotze@itc.rwth-aachen.de   // CHECK: {{^}}{{[0-f]+}}: ompt_event_reduction_end:
493356e268Sprotze@itc.rwth-aachen.de   // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}
503356e268Sprotze@itc.rwth-aachen.de 
513356e268Sprotze@itc.rwth-aachen.de   return 0;
523356e268Sprotze@itc.rwth-aachen.de }
53