-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
61 lines (48 loc) · 778 Bytes
/
main.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
56
57
58
59
60
61
#include <stdio.h>
extern int a(int, int);
int steer(int i, int ifun);
#pragma acc routine(steer) seq
extern int b(int);
#pragma acc routine(b) seq
extern int c(int);
#pragma acc routine(c) seq
int main() {
int x;
x = a(1000, 1);
printf("x=%d\n", x);
x = a(1000, 2);
printf("x=%d\n", x);
return 0;
}
int a(int n, int ifun) {
int i, x;
x = 0;
#pragma acc parallel loop
for (int i = 0; i < n ; ++i) {
#pragma acc atomic update
x += steer(i, ifun);
}
return x;
}
int b(int i) {
return 2*i;
}
int c(int i) {
return 3*i;
}
int steer(int i, int ifun) {
int x;
#if 1
switch (ifun) {
case 1: x = b(i); break;
case 2: x = c(i); break;
}
#else
if (ifun == 1) {
x = b(i);
}else{
x = c(i);
}
#endif
return x;
}