xref: /llvm-project/openmp/tools/archer/tests/races/task-dependency.c (revision 26b675d65eb2d1f117a39eee965652f590373232)
12b8115b1Sprotze@itc.rwth-aachen.de /*
24c6a098aSKazuaki Ishizaki  * task-dependency.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[]) {
22*26b675d6SJoachim Protze   int var = 0, a = 0, b = 0;
232b8115b1Sprotze@itc.rwth-aachen.de 
244acc2f29SJoachim Protze #pragma omp parallel num_threads(8) shared(var, a)
252b8115b1Sprotze@itc.rwth-aachen.de #pragma omp master
262b8115b1Sprotze@itc.rwth-aachen.de   {
27*26b675d6SJoachim Protze #pragma omp task shared(var, a, b) depend(out : var)
282b8115b1Sprotze@itc.rwth-aachen.de     {
292b8115b1Sprotze@itc.rwth-aachen.de       OMPT_SIGNAL(a);
302b8115b1Sprotze@itc.rwth-aachen.de       var++;
31*26b675d6SJoachim Protze       OMPT_SIGNAL(b);
322b8115b1Sprotze@itc.rwth-aachen.de     }
332b8115b1Sprotze@itc.rwth-aachen.de 
342b8115b1Sprotze@itc.rwth-aachen.de #pragma omp task shared(a) depend(in : var)
352b8115b1Sprotze@itc.rwth-aachen.de     {
362b8115b1Sprotze@itc.rwth-aachen.de       OMPT_SIGNAL(a);
372b8115b1Sprotze@itc.rwth-aachen.de       OMPT_WAIT(a, 3);
382b8115b1Sprotze@itc.rwth-aachen.de     }
392b8115b1Sprotze@itc.rwth-aachen.de 
40*26b675d6SJoachim Protze #pragma omp task shared(var, b) // depend(in: var) is missing here!
412b8115b1Sprotze@itc.rwth-aachen.de     {
42*26b675d6SJoachim Protze       OMPT_WAIT(b, 1);
432b8115b1Sprotze@itc.rwth-aachen.de       var++;
442b8115b1Sprotze@itc.rwth-aachen.de       OMPT_SIGNAL(a);
452b8115b1Sprotze@itc.rwth-aachen.de     }
462b8115b1Sprotze@itc.rwth-aachen.de 
472b8115b1Sprotze@itc.rwth-aachen.de     // Give other thread time to steal the task.
482b8115b1Sprotze@itc.rwth-aachen.de     OMPT_WAIT(a, 2);
492b8115b1Sprotze@itc.rwth-aachen.de   }
502b8115b1Sprotze@itc.rwth-aachen.de 
512b8115b1Sprotze@itc.rwth-aachen.de   int error = (var != 2);
522b8115b1Sprotze@itc.rwth-aachen.de   fprintf(stderr, "DONE\n");
532b8115b1Sprotze@itc.rwth-aachen.de   return error;
542b8115b1Sprotze@itc.rwth-aachen.de }
552b8115b1Sprotze@itc.rwth-aachen.de 
562b8115b1Sprotze@itc.rwth-aachen.de // CHECK: WARNING: ThreadSanitizer: data race
572b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT:   {{(Write|Read)}} of size 4
58*26b675d6SJoachim Protze // CHECK-NEXT: #0 {{.*}}task-dependency.c:43
592b8115b1Sprotze@itc.rwth-aachen.de // CHECK:   Previous write of size 4
602b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NEXT: #0 {{.*}}task-dependency.c:30
612b8115b1Sprotze@itc.rwth-aachen.de // CHECK: DONE
622b8115b1Sprotze@itc.rwth-aachen.de // CHECK: ThreadSanitizer: reported 1 warnings
63