-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinspect_reduction.cpp
More file actions
50 lines (42 loc) · 1 KB
/
Copy pathinspect_reduction.cpp
File metadata and controls
50 lines (42 loc) · 1 KB
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 <cstdio>
#include <omp.h>
int inspectAdder(int a, int b)
{
#ifdef __wasm__
printf("A = %i B=%i\n", &a, &b);
#else
printf("A = %p B=%p\n", &a, &b);
#endif
return a + b;
}
#pragma omp declare reduction(inspectAdd \
:int : omp_out = inspectAdder(omp_out, omp_in)) initializer(omp_priv = 0)
int main()
{
int x = 0;
int y = 0;
#ifdef __wasm__
printf("Result before: %i (%i) %i (%i)\n", x, &x, y, &y);
#else
printf("Result before: %i (%p) %i (%p)\n", x, &x, y, &y);
#endif
#pragma omp parallel num_threads(10) reduction(inspectAdd : x, y)
{
x += 1;
y += 2;
}
if (x != 10) {
printf("Reduction x result unexpected: %i\n", x);
return 1;
}
if (y != 20) {
printf("Reduction y result unexpected: %i\n", y);
return 1;
}
#ifdef __wasm__
printf("Result after: %i (%i) %i (%i)\n", x, &x, y, &y);
#else
printf("Result after: %i (%p) %i (%p)\n", x, &x, y, &y);
#endif
return 0;
}