source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB148-critical1-orig-gpu-yes.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
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/*
11This example is referred from DataRaceOnAccelerator : A Micro-benchmark Suite for Evaluating
12Correctness Tools Targeting Accelerators.
13Though we have used critical directive to ensure that addition and subtraction are not overlapped,
14due to different locks addlock@30:26 and sublock@33:26 interleave each others operation.
15Data Race pairs, var@31:5 and var@34:5
16*/
17
18#include <omp.h>
19#include <stdio.h>
20
21#define N 100
22
23int var = 0;
24
25int main(){
26
27 #pragma omp target map(tofrom:var) device(0)
28 #pragma omp teams distribute parallel for
29 for(int i=0; i<N; i++){
30 #pragma omp critical(addlock)
31 var++;
32
33 #pragma omp critical(sublock)
34 var -= 2;
35 }
36
37 printf("%d\n",var);
38
39 return 0;
40}
Note: See TracBrowser for help on using the repository browser.