-
Notifications
You must be signed in to change notification settings - Fork 64
/
target_mapper.2.c
55 lines (46 loc) · 1.26 KB
/
target_mapper.2.c
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
51
52
53
54
55
/*
* @@name: target_mapper.2
* @@type: C
* @@operation: compile
* @@expect: success
* @@version: omp_5.0
*/
#include <stdio.h>
// N MUST BE EVEN
#define N 100
typedef struct dzmat
{
double r_m[N][N];
double i_m[N][N];
} dzmat_t;
#pragma omp declare mapper( top_id: dzmat_t v) \
map(v.r_m[0:N/2][0:N], \
v.i_m[0:N/2][0:N] )
#pragma omp declare mapper(bottom_id: dzmat_t v) \
map(v.r_m[N/2:N/2][0:N], \
v.i_m[N/2:N/2][0:N] )
//initialization
void dzmat_init(dzmat_t *z, int is, int ie, int n);
//matrix add: c=a+b
void host_add( dzmat_t *a, dzmat_t *b, dzmat_t *c, int n);
int main()
{
dzmat_t a,b,c;
int is,ie;
is=0; ie=N/2-1; //top N/2 rows on device 0
#pragma omp target map(mapper(top_id), tofrom: a,b) device(0) \
firstprivate(is,ie) nowait
{
dzmat_init(&a,is,ie,N);
dzmat_init(&b,is,ie,N);
}
is=N/2; ie=N-1; //bottom N/2 rows on device 1
#pragma omp target map(mapper(bottom_id), tofrom: a,b) device(1) \
firstprivate(is,ie) nowait
{
dzmat_init(&a,is,ie,N);
dzmat_init(&b,is,ie,N);
}
#pragma omp taskwait
host_add(&a,&b,&c,N);
}