12b8115b1Sprotze@itc.rwth-aachen.de /* 22b8115b1Sprotze@itc.rwth-aachen.de * parallel-reduction.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.deint main(int argc, char *argv[]) { 212b8115b1Sprotze@itc.rwth-aachen.de int var = 0; 222b8115b1Sprotze@itc.rwth-aachen.de 232b8115b1Sprotze@itc.rwth-aachen.de // Number of threads is empirical: We need enough threads so that 242b8115b1Sprotze@itc.rwth-aachen.de // the reduction is really performed hierarchically in the barrier! 252b8115b1Sprotze@itc.rwth-aachen.de #pragma omp parallel num_threads(5) reduction(+ : var) 262b8115b1Sprotze@itc.rwth-aachen.de { var = 1; } 272b8115b1Sprotze@itc.rwth-aachen.de 282b8115b1Sprotze@itc.rwth-aachen.de fprintf(stderr, "DONE\n"); 292b8115b1Sprotze@itc.rwth-aachen.de int error = (var != 5); 302b8115b1Sprotze@itc.rwth-aachen.de return error; 312b8115b1Sprotze@itc.rwth-aachen.de } 322b8115b1Sprotze@itc.rwth-aachen.de 332b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NOT: ThreadSanitizer: data race 342b8115b1Sprotze@itc.rwth-aachen.de // CHECK-NOT: ThreadSanitizer: reported 352b8115b1Sprotze@itc.rwth-aachen.de // CHECK: DONE 36