source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB147-critical1-orig-gpu-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: 982 bytes
Line 
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/*
11Concurrent access on same variable var@29 and var@32 leads to the race condition if two different
12locks are used. This is the reason here we have used the atomic directive to ensure that addition
13and subtraction are not interleaved. No data race pairs.
14*/
15
16#include <omp.h>
17#include <stdio.h>
18
19#define N 100
20
21int var = 0;
22
23int main(){
24
25 #pragma omp target map(tofrom:var) device(0)
26 #pragma omp teams distribute parallel for
27 for(int i=0; i<N; i++){
28 #pragma omp atomic
29 var++;
30
31 #pragma omp atomic
32 var -= 2;
33 }
34
35 printf("%d\n",var);
36 return 0;
37}
Note: See TracBrowser for help on using the repository browser.