source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB149-missingdata1-orig-gpu-no.c@ 8190175

main test-branch
Last change on this file since 8190175 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/*
11Data Race free matrix vector multiplication using target construct.
12*/
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <omp.h>
17#define C 100
18
19int *a;
20int *b;
21int *c;
22
23int main(){
24 a = malloc(C*sizeof(int));
25 b = malloc(C*C*sizeof(int));
26 c = malloc(C*sizeof(int));
27
28 for(int i=0; i<C; i++){
29 for(int j=0; j<C; j++){
30 b[j+i*C]=1;
31 }
32 a[i]=1;
33 c[i]=0;
34 }
35
36 #pragma omp target map(to:a[0:C],b[0:C*C]) map(tofrom:c[0:C]) device(0)
37 {
38 #pragma omp teams distribute parallel for
39 for(int i=0; i<C; i++){
40 for(int j=0; j<C; j++){
41 c[i]+=b[j+i*C]*a[j];
42 }
43 }
44 }
45
46 for(int i=0; i<C; i++){
47 if(c[i]!=C){
48 printf("Data Race\n");
49 return 1;
50 }
51 }
52
53 free(a);
54 free(b);
55 free(c);
56
57 return 0;
58}
Note: See TracBrowser for help on using the repository browser.