forked from UK-MAC/CloverLeaf_OpenACC_3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_chunk_kernel.f90
231 lines (214 loc) · 8.04 KB
/
generate_chunk_kernel.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
!Crown Copyright 2012 AWE.
!
! This file is part of CloverLeaf.
!
! CloverLeaf is free software: you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the
! Free Software Foundation, either version 3 of the License, or (at your option)
! any later version.
!
! CloverLeaf is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
! details.
!
! You should have received a copy of the GNU General Public License along with
! CloverLeaf. If not, see http://www.gnu.org/licenses/.
!> @brief Fortran mesh chunk generator
!> @author Wayne Gaudin
!> @details Generates the field data on a mesh chunk based on the user specified
!> input for the states.
!>
!> Note that state one is always used as the background state, which is then
!> overwritten by further state definitions.
MODULE generate_chunk_kernel_module
CONTAINS
SUBROUTINE generate_chunk_kernel(x_min,x_max,y_min,y_max,z_min,z_max, &
vertexx, &
vertexy, &
vertexz, &
cellx, &
celly, &
cellz, &
density0, &
energy0, &
xvel0, &
yvel0, &
zvel0, &
number_of_states, &
state_density, &
state_energy, &
state_xvel, &
state_yvel, &
state_zvel, &
state_xmin, &
state_xmax, &
state_ymin, &
state_ymax, &
state_zmin, &
state_zmax, &
state_radius, &
state_geometry, &
g_rect, &
g_circ, &
g_point)
IMPLICIT NONE
INTEGER :: x_min,x_max,y_min,y_max,z_min,z_max
REAL(KIND=8), DIMENSION(x_min-2:x_max+3) :: vertexx
REAL(KIND=8), DIMENSION(y_min-2:y_max+3) :: vertexy
REAL(KIND=8), DIMENSION(z_min-2:z_max+3) :: vertexz
REAL(KIND=8), DIMENSION(x_min-2:x_max+2) :: cellx
REAL(KIND=8), DIMENSION(y_min-2:y_max+2) :: celly
REAL(KIND=8), DIMENSION(z_min-2:z_max+2) :: cellz
REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2,z_min-2:z_max+2) :: density0,energy0
REAL(KIND=8), DIMENSION(x_min-2:x_max+3,y_min-2:y_max+3,z_min-2:z_max+3) :: xvel0,yvel0,zvel0
INTEGER :: number_of_states
REAL(KIND=8), DIMENSION(number_of_states) :: state_density
REAL(KIND=8), DIMENSION(number_of_states) :: state_energy
REAL(KIND=8), DIMENSION(number_of_states) :: state_xvel
REAL(KIND=8), DIMENSION(number_of_states) :: state_yvel
REAL(KIND=8), DIMENSION(number_of_states) :: state_zvel
REAL(KIND=8), DIMENSION(number_of_states) :: state_xmin
REAL(KIND=8), DIMENSION(number_of_states) :: state_xmax
REAL(KIND=8), DIMENSION(number_of_states) :: state_ymin
REAL(KIND=8), DIMENSION(number_of_states) :: state_ymax
REAL(KIND=8), DIMENSION(number_of_states) :: state_zmin
REAL(KIND=8), DIMENSION(number_of_states) :: state_zmax
REAL(KIND=8), DIMENSION(number_of_states) :: state_radius
INTEGER , DIMENSION(number_of_states) :: state_geometry
INTEGER :: g_rect
INTEGER :: g_circ
INTEGER :: g_point
REAL(KIND=8) :: radius,x_cent,y_cent,z_cent
INTEGER :: state
INTEGER :: j,k,jt,kt,l,lt
! State 1 is always the background state
!$ACC DATA
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min-2,z_max+2
!$ACC LOOP INDEPENDENT
DO k=y_min-2,y_max+2
!$ACC LOOP INDEPENDENT
DO j=x_min-2,x_max+2
energy0(j,k,l)=state_energy(1)
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min-2,z_max+2
!$ACC LOOP INDEPENDENT
DO k=y_min-2,y_max+2
!$ACC LOOP INDEPENDENT
DO j=x_min-2,x_max+2
density0(j,k,l)=state_density(1)
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min-2,z_max+2
!$ACC LOOP INDEPENDENT
DO k=y_min-2,y_max+2
!$ACC LOOP INDEPENDENT
DO j=x_min-2,x_max+2
xvel0(j,k,l)=state_xvel(1)
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min-2,z_max+2
!$ACC LOOP INDEPENDENT
DO k=y_min-2,y_max+2
!$ACC LOOP INDEPENDENT
DO j=x_min-2,x_max+2
yvel0(j,k,l)=state_yvel(1)
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min-2,z_max+2
!$ACC LOOP INDEPENDENT
DO k=y_min-2,y_max+2
!$ACC LOOP INDEPENDENT
DO j=x_min-2,x_max+2
zvel0(j,k,l)=state_zvel(1)
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
DO state=2,number_of_states
! Could the velocity setting be thread unsafe?
x_cent=state_xmin(state)
y_cent=state_ymin(state)
z_cent=state_zmin(state)
!$ACC KERNELS
!$ACC LOOP INDEPENDENT
DO l=z_min-2,z_max+2
!$ACC LOOP INDEPENDENT
DO k=y_min-2,y_max+2
!$ACC LOOP INDEPENDENT PRIVATE(RADIUS)
DO j=x_min-2,x_max+2
IF(state_geometry(state).EQ.g_rect ) THEN
IF(vertexx(j+1).GE.state_xmin(state).AND.vertexx(j).LT.state_xmax(state)) THEN
IF(vertexy(k+1).GE.state_ymin(state).AND.vertexy(k).LT.state_ymax(state)) THEN
IF(vertexz(l+1).GE.state_zmin(state).AND.vertexz(l).LT.state_zmax(state)) THEN
energy0(j,k,l)=state_energy(state)
density0(j,k,l)=state_density(state)
DO lt=l,l+1
DO kt=k,k+1
DO jt=j,j+1
xvel0(jt,kt,lt)=state_xvel(state)
yvel0(jt,kt,lt)=state_yvel(state)
zvel0(jt,kt,lt)=state_zvel(state)
ENDDO
ENDDO
ENDDO
ENDIF
ENDIF
ENDIF
ELSEIF(state_geometry(state).EQ.g_circ ) THEN
radius=SQRT((cellx(j)-x_cent)*(cellx(j)-x_cent)+(celly(k)-y_cent)*(celly(k)-y_cent)+(cellz(l)-z_cent)*(cellz(l)-z_cent))
IF(radius.LE.state_radius(state))THEN
energy0(j,k,l)=state_energy(state)
density0(j,k,l)=state_density(state)
DO lt=l,l+1
DO kt=k,k+1
DO jt=j,j+1
xvel0(jt,kt,lt)=state_xvel(state)
yvel0(jt,kt,lt)=state_yvel(state)
zvel0(jt,kt,lt)=state_zvel(state)
ENDDO
ENDDO
ENDDO
ENDIF
ELSEIF(state_geometry(state).EQ.g_point) THEN
IF(vertexx(j).EQ.x_cent .AND. vertexy(k).EQ.y_cent .AND. vertexz(l).EQ.z_cent) THEN
energy0(j,k,l)=state_energy(state)
density0(j,k,l)=state_density(state)
DO lt=l,l+1
DO kt=k,k+1
DO jt=j,j+1
xvel0(jt,kt,lt)=state_xvel(state)
yvel0(jt,kt,lt)=state_yvel(state)
zvel0(jt,kt,lt)=state_zvel(state)
ENDDO
ENDDO
ENDDO
ENDIF
ENDIF
ENDDO
ENDDO
ENDDO
!$ACC END KERNELS
ENDDO
!$ACC END DATA
END SUBROUTINE generate_chunk_kernel
END MODULE generate_chunk_kernel_module