Skip to content

Commit 842a1fb

Browse files
authored
Merge pull request #37 from ajarmusch/serial_loop_gang_blocking
New Serial Tests: serial_loop_gang_blocking
2 parents 3ae0598 + 7cd539e commit 842a1fb

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef T1
2+
!T1:loop,V:2.6-2.7
3+
LOGICAL FUNCTION test1()
4+
IMPLICIT NONE
5+
INCLUDE "acc_testsuite.Fh"
6+
REAL(8),DIMENSION(LOOPCOUNT):: a, b, c
7+
INTEGER:: multiplier
8+
INTEGER:: x
9+
INTEGER:: errors
10+
11+
errors = 0
12+
13+
SEEDDIM(1) = 1
14+
# ifdef SEED
15+
SEEDDIM(1) = SEED
16+
# endif
17+
CALL RANDOM_SEED(PUT=SEEDDIM)
18+
19+
CALL RANDOM_NUMBER(a)
20+
CALL RANDOM_NUMBER(b)
21+
c = 0
22+
23+
!$acc data copyin(a(1:LOOPCOUNT), b(1:LOOPCOUNT)) copyout(c(1:LOOPCOUNT))
24+
!$acc serial
25+
!$acc loop gang
26+
DO x = 1, LOOPCOUNT
27+
c(x) = (a(x) + b(x)) * multiplier
28+
END DO
29+
multiplier = multiplier + 1
30+
!$acc loop gang
31+
DO x = 1, LOOPCOUNT
32+
c(x) = c(x) + ((a(x) + b(x)) * multiplier)
33+
END DO
34+
!$acc end serial
35+
!$acc end data
36+
37+
DO x = 1, LOOPCOUNT
38+
IF (abs(c(x) - (3 * (a(x) + b(x)))) .gt. PRECISION) THEN
39+
errors = errors + 1
40+
END IF
41+
END DO
42+
43+
IF (errors .eq. 0) THEN
44+
test1 = .FALSE.
45+
ELSE
46+
test1 = .TRUE.
47+
END IF
48+
END
49+
#endif
50+
51+
PROGRAM main
52+
IMPLICIT NONE
53+
INTEGER :: failcode, testrun
54+
LOGICAL :: failed
55+
INCLUDE "acc_testsuite.Fh"
56+
#ifndef T1
57+
LOGICAL :: test1
58+
#endif
59+
failed = .FALSE.
60+
failcode = 0
61+
#ifndef T1
62+
DO testrun = 1, NUM_TEST_CALLS
63+
failed = failed .or. test1()
64+
END DO
65+
IF (failed) THEN
66+
failcode = failcode + 2 ** 0
67+
failed = .FALSE.
68+
END IF
69+
#endif
70+
CALL EXIT (failcode)
71+
END PROGRAM

Tests/serial_loop_gang_blocking.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "acc_testsuite.h"
2+
#ifndef T1
3+
//T1:serial,loop,V:2.6-2.7
4+
int test1(){
5+
int err = 0;
6+
srand(SEED);
7+
real_t * a = (real_t *)malloc(n * sizeof(real_t));
8+
real_t * b = (real_t *)malloc(n * sizeof(real_t));
9+
real_t * c = (real_t *)malloc(n * sizeof(real_t));
10+
real_t multiplyer = 1;
11+
12+
for (int x = 0; x < n; ++x){
13+
a[x] = rand() / (real_t)(RAND_MAX / 10);
14+
b[x] = rand() / (real_t)(RAND_MAX / 10);
15+
c[x] = 0.0;
16+
}
17+
18+
#pragma acc data copyin(a[0:n], b[0:n]) copyout(c[0:n])
19+
{
20+
#pragma acc serial
21+
{
22+
#pragma acc loop gang
23+
for (int x = 0; x < n; ++x){
24+
c[x] = (a[x] + b[x]) * multiplyer;
25+
}
26+
multiplyer += 1;
27+
#pragma acc loop gang
28+
for (int x = 0; x < n; ++x){
29+
c[x] += (a[x] + b[x]) * multiplyer;
30+
}
31+
}
32+
}
33+
34+
for (int x = 0; x < n; ++x){
35+
if (fabs(c[x] - 3 * (a[x] + b[x])) > PRECISION){
36+
err + 1;
37+
break;
38+
}
39+
}
40+
41+
return err;
42+
}
43+
#endif
44+
45+
int main(){
46+
int failcode = 0;
47+
int failed;
48+
#ifndef T1
49+
failed = 0;
50+
for (int x = 0; x < NUM_TEST_CALLS; ++x){
51+
failed = failed + test1();
52+
}
53+
if (failed != 0){
54+
failcode = failcode + (1 << 0);
55+
}
56+
#endif
57+
return failcode;
58+
}

0 commit comments

Comments
 (0)