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.4 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 | /*This example is referred from DRACC by Adrian Schmitz et al.
|
|---|
| 11 | Vector addition followed by multiplication involving the same var should have a barrier in between.
|
|---|
| 12 | omp distribute directive does not have implicit barrier. This will cause data race.
|
|---|
| 13 | Data Race Pair: b[i]@42:19 and b[i]@47:9
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | #include <stdio.h>
|
|---|
| 17 | #include <omp.h>
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #define N 100
|
|---|
| 20 | #define C 16
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | int a;
|
|---|
| 24 | int b[C];
|
|---|
| 25 | int c[C];
|
|---|
| 26 | int temp[C];
|
|---|
| 27 |
|
|---|
| 28 | int main(){
|
|---|
| 29 | for(int i=0; i<C; i++){
|
|---|
| 30 | b[i]=0;
|
|---|
| 31 | c[i]=2;
|
|---|
| 32 | temp[i]=0;
|
|---|
| 33 | }
|
|---|
| 34 | a=2;
|
|---|
| 35 |
|
|---|
| 36 | #pragma omp target map(tofrom:b[0:C]) map(to:c[0:C],temp[0:C],a) device(0)
|
|---|
| 37 | {
|
|---|
| 38 | #pragma omp teams
|
|---|
| 39 | for(int i=0; i<N ;i++){
|
|---|
| 40 | #pragma omp distribute
|
|---|
| 41 | for(int i=0; i<C; i++){
|
|---|
| 42 | temp[i] = b[i] + c[i];
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | #pragma omp distribute
|
|---|
| 46 | for(int i=C-1; i>=0; i--){
|
|---|
| 47 | b[i] = temp[i] * a;
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | int val = 0;
|
|---|
| 53 |
|
|---|
| 54 | for(int i=0; i<N; i++){
|
|---|
| 55 | val = val + 2;
|
|---|
| 56 | val = val * 2;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | for(int i=0; i<C; i++){
|
|---|
| 60 | if(b[i]!=val){
|
|---|
| 61 | printf("index: %d val: %d\n",i, b[i]);
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | return 0;
|
|---|
| 66 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.