-
Notifications
You must be signed in to change notification settings - Fork 15
/
atomic_capture_assign_expr_divided_x.F90
165 lines (154 loc) · 4.58 KB
/
atomic_capture_assign_expr_divided_x.F90
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
RECURSIVE FUNCTION IS_POSSIBLE_2(a, b, length, init) RESULT(POSSIBLE)
INTEGER, INTENT(IN) :: length
REAL(8), INTENT(IN) :: init
REAL(8),DIMENSION(length), INTENT(IN) :: a
REAL(8),DIMENSION(length), INTENT(IN) :: b
REAL(8),DIMENSION(length - 1) :: passed_a
REAL(8),DIMENSION(length - 1) :: passed_b
real(8) :: holder
LOGICAL :: POSSIBLE
INTEGER :: x, y
REAL(8):: mindif
IF (length .lt. 10) THEN
WRITE(*, *) length
END IF
IF (length .eq. 0) THEN
POSSIBLE = .TRUE.
RETURN
END IF
POSSIBLE = .FALSE.
DO x = 1, length
IF (abs(b(x) - init) .lt. (100 - length) * PRECISION) THEN
DO y = 1, x - 1
passed_a(y) = a(y)
passed_b(y) = b(y)
END DO
DO y = x + 1, length
passed_a(y - 1) = a(y)
passed_b(y - 1) = b(y)
END DO
holder = a(x) / init
IF (IS_POSSIBLE_2(passed_a, passed_b, length - 1, holder)) THEN
POSSIBLE = .TRUE.
RETURN
END IF
END IF
END DO
END FUNCTION IS_POSSIBLE_2
RECURSIVE FUNCTION IS_POSSIBLE(subset, destination, length, init) RESULT(POSSIBLE)
INTEGER, INTENT(IN) :: length
REAL(8),DIMENSION(length), INTENT(IN) :: subset
REAL(8), INTENT(IN) :: destination
REAL(8), INTENT(IN) :: init
REAL(8),ALLOCATABLE :: passed(:)
REAL(8) :: holder
LOGICAL :: POSSIBLE
INTEGER :: x, y
IF (length .gt. 0) THEN
ALLOCATE(passed(length - 1))
ELSE
IF (abs(init - destination) .lt. (10 - length) * PRECISION) THEN
POSSIBLE = .TRUE.
ELSE
POSSIBLE = .FALSE.
END IF
RETURN
END IF
POSSIBLE = .FALSE.
DO x = 1, length
DO y = 1, x - 1
passed(y) = subset(y)
END DO
DO y = x + 1, length
passed(y - 1) = subset(y)
END DO
holder = subset(x) / init
IF (IS_POSSIBLE(passed, destination, length - 1, holder)) THEN
POSSIBLE = .TRUE.
RETURN
END IF
END DO
END FUNCTION IS_POSSIBLE
#ifndef T1
!T1:construct-independent,atomic,V:2.0-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x, y !Iterators
REAL(8),DIMENSION(LOOPCOUNT, 10):: a !Data
REAL(8),DIMENSION(LOOPCOUNT, 10):: b
REAL(8),DIMENSION(LOOPCOUNT):: totals
REAL(8),DIMENSION(10):: passed
REAL(8),DIMENSION(10):: passed_b
REAL(8) :: holder
INTEGER :: errors = 0
LOGICAL IS_POSSIBLE
LOGICAL IS_POSSIBLE_2
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
totals = 1
!$acc data copyin(a(1:LOOPCOUNT, 1:10)) copy(totals(1:LOOPCOUNT)) copyout(b(1:LOOPCOUNT,1:10))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
DO y = 1, 10
!$acc atomic capture
b(x, y) = totals(x)
totals(x) = a(x, y) / totals(x)
!$acc end atomic
END DO
END DO
!$acc end parallel
!$acc end data
DO x = 1, LOOPCOUNT
DO y = 1, 10
passed(y) = a(x, y)
END DO
holder = 1
IF (IS_POSSIBLE(passed, totals(x), 10, holder) .eqv. .FALSE.) THEN
errors = errors + 1
END IF
END DO
DO x = 1, LOOPCOUNT
DO y = 1, 10
passed(y) = a(x, y)
passed_b(y) = b(x, y)
END DO
holder = 1
IF (IS_POSSIBLE_2(passed, passed_b, 10, holder) .eqv. .FALSE.) THEN
errors = errors + 1
END IF
END DO
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM