source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB121-reduction-orig-no.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 1.1 KB
RevLine 
[e3f356c]1/*
2!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
3!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
4!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
5!!!
6!!! SPDX-License-Identifier: (BSD-3-Clause)
7!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
8*/
9
10/*
11Number of threads is empirical: We need enough threads so that
12the reduction is really performed hierarchically in the barrier!
13There is no data race.
14*/
15
16
17#include <omp.h>
18#include <stdio.h>
19
20int main(int argc, char* argv[])
21{
22 int var = 0, i, res;
23 int sum1 = 0;
24 int sum2 = 0;
25
26 res = omp_get_max_threads();
27
28 #pragma omp parallel reduction(+: var)
29 {
30 #pragma omp for schedule(static) reduction(+: sum1)
31 for (i=0; i<5; i++)
32 sum1+=i;
33 #pragma omp for schedule(static) reduction(+: sum2)
34 for (i=0; i<5; i++)
35 sum2+=i;
36
37 var = sum1 + sum2;
38 }
39
40 int error = (var != 20*res);
41 if (error) printf("%d %d\n",var,20*res);
42 return error;
43}
Note: See TracBrowser for help on using the repository browser.