brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · b91579f Raw
47 lines · c
1/*2 * parallel-reduction-nowait.c -- Archer testcase3 */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-exception11//12//===----------------------------------------------------------------------===//13 14 15// RUN: %libarcher-compile-and-run | FileCheck %s16// REQUIRES: tsan17#include <omp.h>18#include <stdio.h>19 20int 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 that26// 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, "DONE\n");40  int error = (var != 100);41  return error;42}43 44// CHECK-NOT: ThreadSanitizer: data race45// CHECK-NOT: ThreadSanitizer: reported46// CHECK: DONE47