-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_target_update_data.cpp
More file actions
50 lines (39 loc) · 936 Bytes
/
09_target_update_data.cpp
File metadata and controls
50 lines (39 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "stdio.h"
#define N 10
#define L (N-5)
int B[N];
#pragma omp declare target(B)
void update( int* B1, int l, int n )
{
for(int i=l; i< n; i++)
B1[i] *= 2;
}
int main()
{
int errors = 0;
// initialize
for(int i=0; i< N; i++)
B[i] = i;
// make host and device consistent
#pragma omp target update to( B )
#pragma omp target
for(int i=L; i< N; i++)
B[i] = i+1;
// gets the last L elements in B from the accelerator, makes
// the host consistent
#pragma omp target update from( B[L:N-L] )
update( B, L, N );
// gets the last L elements in B from the host, makes
// the accelerator consistent
#pragma omp target update to( B[L:N-L])
// error check
for(int i=0; i< L; i++)
if( B[i] != i ) errors++;
for(int i=L; i< N; i++)
if( B[i] != (i+1)*2 ) errors++;
if( errors != 0 )
printf( "Failed!\n" );
else
printf( "Success!\n" );
return 0;
}