-
Notifications
You must be signed in to change notification settings - Fork 16
/
atomic_structured_x_multiply_expr_assign.cpp
106 lines (99 loc) · 2.89 KB
/
atomic_structured_x_multiply_expr_assign.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "acc_testsuite.h"
bool is_possible(real_t* a, real_t* b, int length, real_t prev){
if (length == 0){
return true;
}
real_t *passed_a = new real_t[(length - 1)];
real_t *passed_b = new real_t[(length - 1)];
for (int x = 0; x < length; ++x){
if (fabs(b[x] - (a[x] * prev)) < PRECISION){
for (int y = 0; y < x; ++y){
passed_a[y] = a[y];
passed_b[y] = b[y];
}
for (int y = x + 1; y < length; ++y){
passed_a[y - 1] = a[y];
passed_b[y - 1] = b[y];
}
if (is_possible(passed_a, passed_b, length - 1, b[x])){
delete[] passed_a;
delete[] passed_b;
return true;
}
}
}
delete[] passed_a;
delete[] passed_b;
return false;
}
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *totals = new real_t[(n/10 + 1)];
real_t *totals_comparison = new real_t[(n/10 + 1)];
real_t * passed_ab = new real_t[10];
real_t * passed_c = new real_t[10];
int passed_indexer;
int absolute_indexer;
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
}
for (int x = 0; x < n/10 + 1; ++x){
totals[x] = 1;
totals_comparison[x] = 1;
}
#pragma acc data copyin(a[0:n], b[0:n]) copy(totals[0:n/10 + 1]) copyout(c[0:n])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc atomic capture
{
totals[x%(n/10 + 1)] = totals[x%(n/10 + 1)] * (a[x] + b[x]);
c[x] = totals[x%(n/10 + 1)];
}
}
}
}
for (int x = 0; x < n; ++x){
totals_comparison[x%(n/10 + 1)] *= a[x] + b[x];
}
for (int x = 0; x < 10; ++x){
if (fabs(totals_comparison[x] - totals[x]) > PRECISION * totals_comparison[x]){
err += 1;
break;
}
}
for (int x = 0; x < n/10 + 1; ++x){
for (passed_indexer = 0, absolute_indexer = x; absolute_indexer < n; passed_indexer++, absolute_indexer += n/10 + 1){
passed_ab[passed_indexer] = a[absolute_indexer] + b[absolute_indexer];
passed_c[passed_indexer] = c[absolute_indexer];
}
if (!is_possible(passed_ab, passed_c, passed_indexer, 1)){
err++;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}