| 1 | /* |
| 2 | * parallel-reduction-nowait.c -- Archer testcase |
| 3 | */ |
| 4 | |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | // |
| 7 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 8 | // |
| 9 | // See tools/archer/LICENSE.txt for details. |
| 10 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | |
| 15 | // RUN: %libarcher-compile-and-run | FileCheck %s |
| 16 | // REQUIRES: tsan |
| 17 | #include <omp.h> |
| 18 | #include <stdio.h> |
| 19 | |
| 20 | int main(int argc, char *argv[]) { |
| 21 | int var = 0, i; |
| 22 | int sum1 = 0; |
| 23 | int sum2 = 0; |
| 24 | |
| 25 | // Number of threads is empirical: We need enough threads so that |
| 26 | // the reduction is really performed hierarchically in the barrier! |
| 27 | #pragma omp parallel num_threads(5) reduction(+ : var) |
| 28 | { |
| 29 | #pragma omp for schedule(static) nowait reduction(+ : sum1) |
| 30 | for (i = 0; i < 5; i++) |
| 31 | sum1 += i; |
| 32 | #pragma omp for schedule(static) reduction(+ : sum2) |
| 33 | for (i = 0; i < 5; i++) |
| 34 | sum2 += i; |
| 35 | |
| 36 | var = sum1 + sum2; |
| 37 | } |
| 38 | |
| 39 | fprintf(stderr, format: "DONE\n" ); |
| 40 | int error = (var != 100); |
| 41 | return error; |
| 42 | } |
| 43 | |
| 44 | // CHECK-NOT: ThreadSanitizer: data race |
| 45 | // CHECK-NOT: ThreadSanitizer: reported |
| 46 | // CHECK: DONE |
| 47 | |