xref: /llvm-project/openmp/tools/archer/tests/races/task-taskwait-nested.c (revision 4acc2f29a278ff2a0a4d683dd6d706cc2f7123fd)
12b8115b1Sprotze@itc.rwth-aachen.de /*
22b8115b1Sprotze@itc.rwth-aachen.de  * task-taskwait-nested.c -- Archer testcase
32b8115b1Sprotze@itc.rwth-aachen.de  */
42b8115b1Sprotze@itc.rwth-aachen.de //===----------------------------------------------------------------------===//
52b8115b1Sprotze@itc.rwth-aachen.de //
62b8115b1Sprotze@itc.rwth-aachen.de // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
72b8115b1Sprotze@itc.rwth-aachen.de //
82b8115b1Sprotze@itc.rwth-aachen.de // See tools/archer/LICENSE.txt for details.
92b8115b1Sprotze@itc.rwth-aachen.de // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
102b8115b1Sprotze@itc.rwth-aachen.de //
112b8115b1Sprotze@itc.rwth-aachen.de //===----------------------------------------------------------------------===//
122b8115b1Sprotze@itc.rwth-aachen.de 
132b8115b1Sprotze@itc.rwth-aachen.de // RUN: %libarcher-compile-and-run-race | FileCheck %s
14fdc9dfc8SJoachim Protze // RUN: %libarcher-compile-and-run-race-noserial | FileCheck %s
1577ad98c8Sprotze@itc.rwth-aachen.de // REQUIRES: tsan
1684637408SJoachim Protze #include "ompt/ompt-signal.h"
172b8115b1Sprotze@itc.rwth-aachen.de #include <omp.h>
182b8115b1Sprotze@itc.rwth-aachen.de #include <stdio.h>
192b8115b1Sprotze@itc.rwth-aachen.de #include <unistd.h>
202b8115b1Sprotze@itc.rwth-aachen.de 
main(int argc,char * argv[])212b8115b1Sprotze@itc.rwth-aachen.de int main(int argc, char *argv[]) {
222b8115b1Sprotze@itc.rwth-aachen.de   int var = 0, a = 0;
232b8115b1Sprotze@itc.rwth-aachen.de 
24*4acc2f29SJoachim Protze #pragma omp parallel num_threads(8) shared(var, a)
252b8115b1Sprotze@itc.rwth-aachen.de #pragma omp master
262b8115b1Sprotze@itc.rwth-aachen.de   {
272b8115b1Sprotze@itc.rwth-aachen.de #pragma omp task shared(var, a)
282b8115b1Sprotze@itc.rwth-aachen.de     {
292b8115b1Sprotze@itc.rwth-aachen.de #pragma omp task shared(var, a)
302b8115b1Sprotze@itc.rwth-aachen.de       {
312b8115b1Sprotze@itc.rwth-aachen.de         // wait for master to pass the taskwait
322b8115b1Sprotze@itc.rwth-aachen.de         OMPT_SIGNAL(a);
332b8115b1Sprotze@itc.rwth-aachen.de         OMPT_WAIT(a, 2);
342b8115b1Sprotze@itc.rwth-aachen.de         var++;
352b8115b1Sprotze@itc.rwth-aachen.de       }
362b8115b1Sprotze@itc.rwth-aachen.de     }
372b8115b1Sprotze@itc.rwth-aachen.de 
382b8115b1Sprotze@itc.rwth-aachen.de     // Give other thread time to steal the task and execute its child.
392b8115b1Sprotze@itc.rwth-aachen.de     OMPT_WAIT(a, 1);
402b8115b1Sprotze@itc.rwth-aachen.de 
412b8115b1Sprotze@itc.rwth-aachen.de // Only directly generated children are guaranteed to be executed.
422b8115b1Sprotze@itc.rwth-aachen.de #pragma omp taskwait
432b8115b1Sprotze@itc.rwth-aachen.de     OMPT_SIGNAL(a);
442b8115b1Sprotze@itc.rwth-aachen.de     var++;
452b8115b1Sprotze@itc.rwth-aachen.de   }
462b8115b1Sprotze@itc.rwth-aachen.de 
472b8115b1Sprotze@itc.rwth-aachen.de   int error = (var != 2);
482b8115b1Sprotze@itc.rwth-aachen.de   fprintf(stderr, "DONE\n");
492b8115b1Sprotze@itc.rwth-aachen.de   return error;
502b8115b1Sprotze@itc.rwth-aachen.de }
512b8115b1Sprotze@itc.rwth-aachen.de 
522b8115b1Sprotze@itc.rwth-aachen.de // CHECK: WARNING: ThreadSanitizer: data race
532b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT:   {{(Write|Read)}} of size 4
542b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT: #0 {{.*}}task-taskwait-nested.c:34
552b8115b1Sprotze@itc.rwth-aachen.de // CHECK:   Previous write of size 4
562b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT: #0 {{.*}}task-taskwait-nested.c:44
572b8115b1Sprotze@itc.rwth-aachen.de // CHECK: DONE
582b8115b1Sprotze@itc.rwth-aachen.de // CHECK: ThreadSanitizer: reported 1 warnings
59