xref: /llvm-project/openmp/tools/archer/tests/parallel/parallel-simple2.c (revision 77ad98c80881ba90bf18ec2780169c60e02c159b)
12b8115b1Sprotze@itc.rwth-aachen.de /*
22b8115b1Sprotze@itc.rwth-aachen.de  * parallel-simple2.c -- Archer testcase
32b8115b1Sprotze@itc.rwth-aachen.de  */
42b8115b1Sprotze@itc.rwth-aachen.de 
52b8115b1Sprotze@itc.rwth-aachen.de //===----------------------------------------------------------------------===//
62b8115b1Sprotze@itc.rwth-aachen.de //
72b8115b1Sprotze@itc.rwth-aachen.de // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
82b8115b1Sprotze@itc.rwth-aachen.de //
92b8115b1Sprotze@itc.rwth-aachen.de // See tools/archer/LICENSE.txt for details.
102b8115b1Sprotze@itc.rwth-aachen.de // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
112b8115b1Sprotze@itc.rwth-aachen.de //
122b8115b1Sprotze@itc.rwth-aachen.de //===----------------------------------------------------------------------===//
132b8115b1Sprotze@itc.rwth-aachen.de 
142b8115b1Sprotze@itc.rwth-aachen.de 
152b8115b1Sprotze@itc.rwth-aachen.de // RUN: %libarcher-compile-and-run  | FileCheck %s
16*77ad98c8Sprotze@itc.rwth-aachen.de // REQUIRES: tsan
172b8115b1Sprotze@itc.rwth-aachen.de #include <omp.h>
182b8115b1Sprotze@itc.rwth-aachen.de #include <stdio.h>
192b8115b1Sprotze@itc.rwth-aachen.de 
main(int argc,char * argv[])202b8115b1Sprotze@itc.rwth-aachen.de int main(int argc, char *argv[]) {
212b8115b1Sprotze@itc.rwth-aachen.de   int var = 0;
222b8115b1Sprotze@itc.rwth-aachen.de 
232b8115b1Sprotze@itc.rwth-aachen.de // Create team of threads so that there is no implicit happens before
242b8115b1Sprotze@itc.rwth-aachen.de // when creating the thread.
252b8115b1Sprotze@itc.rwth-aachen.de #pragma omp parallel num_threads(2)
262b8115b1Sprotze@itc.rwth-aachen.de   {}
272b8115b1Sprotze@itc.rwth-aachen.de 
282b8115b1Sprotze@itc.rwth-aachen.de   var++;
292b8115b1Sprotze@itc.rwth-aachen.de 
302b8115b1Sprotze@itc.rwth-aachen.de #pragma omp parallel num_threads(2) shared(var)
312b8115b1Sprotze@itc.rwth-aachen.de   {
322b8115b1Sprotze@itc.rwth-aachen.de     if (omp_get_thread_num() == 1) {
332b8115b1Sprotze@itc.rwth-aachen.de       var++;
342b8115b1Sprotze@itc.rwth-aachen.de     }
352b8115b1Sprotze@itc.rwth-aachen.de   } // implicit barrier
362b8115b1Sprotze@itc.rwth-aachen.de 
372b8115b1Sprotze@itc.rwth-aachen.de   fprintf(stderr, "DONE\n");
382b8115b1Sprotze@itc.rwth-aachen.de   int error = (var != 2);
392b8115b1Sprotze@itc.rwth-aachen.de   return error;
402b8115b1Sprotze@itc.rwth-aachen.de }
412b8115b1Sprotze@itc.rwth-aachen.de 
422b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NOT: ThreadSanitizer: data race
432b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NOT: ThreadSanitizer: reported
442b8115b1Sprotze@itc.rwth-aachen.de // CHECK: DONE
45