source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB159-nobarrier-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: 1.3 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/*
11Vector addition followed by multiplication involving the same var should have a barrier in between.
12Here we have an implicit barrier after parallel for regions. No data race pair.
13*/
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <omp.h>
18#define N 100
19#define C 8
20
21
22int a;
23int b[C];
24int c[C];
25int temp[C];
26
27int main(){
28 for(int i=0; i<C; i++){
29 b[i]=0;
30 c[i]=2;
31 temp[i]=0;
32 }
33 a=2;
34
35 #pragma omp target map(tofrom:b[0:C]) map(to:c[0:C],temp[0:C],a) device(0)
36 #pragma omp parallel
37 {
38 for(int i=0; i<N ;i++){
39 #pragma omp for
40 for(int i=0; i<C; i++){
41 temp[i] = b[i] + c[i];
42 }
43
44 #pragma omp for
45 for(int i=C-1; i>=0; i--){
46 b[i] = temp[i] * a;
47 }
48 }
49 }
50
51 int val = 0;
52
53 for(int i=0; i<N; i++){
54 val = val + 2;
55 val = val * 2;
56 }
57
58 for(int i=0; i<C; i++){
59 if(b[i]!=val){
60 printf("expected %d real %d \n",val, b[i]);
61 return 0;
62 }
63 }
64
65 return 0;
66}
Note: See TracBrowser for help on using the repository browser.