-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.f90
258 lines (227 loc) · 10.5 KB
/
pack.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
MODULE pack_module
USE definitions_module
USE pack_kernel_module
CONTAINS
FUNCTION zincs(field_type) RESULT(z_inc)
integer :: field_type, z_inc
IF(field_type.EQ.CELL_DATA) THEN
z_inc=0
ELSEIF(field_type.EQ.VERTEX_DATA) THEN
z_inc=1
ELSEIF(field_type.EQ.X_FACE_DATA) THEN
z_inc=0
ELSEIF(field_type.EQ.Y_FACE_DATA) THEN
z_inc=0
ELSEIF(field_type.EQ.Z_FACE_DATA) THEN
z_inc=1
ELSE
z_inc=0
ENDIF
END FUNCTION
FUNCTION yincs(field_type) RESULT(y_inc)
integer :: field_type, y_inc
IF(field_type.EQ.CELL_DATA) THEN
y_inc=0
ELSEIF(field_type.EQ.VERTEX_DATA) THEN
y_inc=1
ELSEIF(field_type.EQ.X_FACE_DATA) THEN
y_inc=0
ELSEIF(field_type.EQ.Y_FACE_DATA) THEN
y_inc=1
ELSEIF(field_type.EQ.Z_FACE_DATA) THEN
y_inc=0
ELSE
y_inc=0
ENDIF
END FUNCTION
FUNCTION xincs(field_type) RESULT(x_inc)
integer :: field_type, x_inc
IF(field_type.EQ.CELL_DATA) THEN
x_inc=0
ELSEIF(field_type.EQ.VERTEX_DATA) THEN
x_inc=1
ELSEIF(field_type.EQ.X_FACE_DATA) THEN
x_inc=1
ELSEIF(field_type.EQ.Y_FACE_DATA) THEN
x_inc=0
ELSEIF(field_type.EQ.Z_FACE_DATA) THEN
x_inc=0
ELSE
x_inc=0
ENDIF
END FUNCTION
SUBROUTINE tea_pack_buffers(chunk, fields, depth, face, mpi_buffer, offsets)
IMPLICIT NONE
INTEGER :: fields(:),depth, chunk
INTEGER :: offsets(:)
REAL(KIND=8) :: mpi_buffer(:)
INTEGER :: face
CALL call_packing_functions(chunk, fields, depth, face, .TRUE., mpi_buffer, offsets)
END SUBROUTINE
SUBROUTINE tea_unpack_buffers(chunk, fields, depth, face, mpi_buffer, offsets)
IMPLICIT NONE
INTEGER :: fields(:),depth, chunk
INTEGER :: offsets(:)
REAL(KIND=8) :: mpi_buffer(:)
INTEGER :: face
CALL call_packing_functions(chunk, fields, depth, face, .FALSE., mpi_buffer, offsets)
END SUBROUTINE
SUBROUTINE call_packing_functions(chunk, fields, depth, face, packing, mpi_buffer, offsets)
IMPLICIT NONE
INTERFACE
SUBROUTINE pack_or_unpack(x_min,x_max,y_min,y_max,z_min,z_max, &
halo_exchange_depth, &
field, mpi_buffer, &
depth, x_inc, y_inc, z_inc, &
buffer_offset)
IMPLICIT NONE
INTEGER :: depth,x_min,x_max,y_min,y_max,z_min, z_max,buffer_offset, x_inc, y_inc,z_inc,halo_exchange_depth
REAL(KIND=8) :: field(x_min-halo_exchange_depth:x_max+halo_exchange_depth,&
y_min-halo_exchange_depth:y_max+halo_exchange_depth,&
z_min-halo_exchange_depth:z_max+halo_exchange_depth)
REAL(KIND=8) :: mpi_buffer(:)
END SUBROUTINE
END INTERFACE
INTEGER :: fields(:),depth, chunk
INTEGER :: offsets(:)
REAL(KIND=8) :: mpi_buffer(:)
INTEGER :: face
LOGICAL :: packing
PROCEDURE(pack_or_unpack), POINTER :: pack_func => NULL()
IF (packing .EQV. .TRUE.) THEN
SELECT CASE (face)
CASE (CHUNK_LEFT)
pack_func => tea_pack_message_left
CASE (CHUNK_RIGHT)
pack_func => tea_pack_message_right
CASE (CHUNK_BOTTOM)
pack_func => tea_pack_message_bottom
CASE (CHUNK_TOP)
pack_func => tea_pack_message_top
CASE (CHUNK_BACK)
pack_func => tea_pack_message_back
CASE (CHUNK_FRONT)
pack_func => tea_pack_message_front
CASE DEFAULT
!call report_error("pack.f90","Invalid face pased to buffer packing")
END SELECT
ELSE
SELECT CASE (face)
CASE (CHUNK_LEFT)
pack_func => tea_unpack_message_left
CASE (CHUNK_RIGHT)
pack_func => tea_unpack_message_right
CASE (CHUNK_BOTTOM)
pack_func => tea_unpack_message_bottom
CASE (CHUNK_TOP)
pack_func => tea_unpack_message_top
CASE (CHUNK_BACK)
pack_func => tea_unpack_message_back
CASE (CHUNK_FRONT)
pack_func => tea_unpack_message_front
CASE DEFAULT
!call report_error("pack.f90","Invalid face pased to buffer packing")
END SELECT
ENDIF
!$OMP PARALLEL
IF(fields(FIELD_DENSITY).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%density, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_DENSITY))
ENDIF
IF(fields(FIELD_ENERGY0).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%energy0, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_ENERGY0))
ENDIF
IF(fields(FIELD_ENERGY1).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%energy1, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_ENERGY1))
ENDIF
IF(fields(FIELD_P).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%vector_p, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_P))
ENDIF
IF(fields(FIELD_U).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%u, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_U))
ENDIF
IF(fields(FIELD_SD).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%vector_sd, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_SD))
ENDIF
IF(fields(FIELD_R).EQ.1) THEN
CALL pack_func(chunks(chunk)%field%x_min, &
chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min, &
chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min, &
chunks(chunk)%field%z_max, &
halo_exchange_depth, &
chunks(chunk)%field%vector_r, &
mpi_buffer, &
depth, &
xincs(CELL_DATA), yincs(CELL_DATA), zincs(CELL_DATA), &
offsets(FIELD_R))
ENDIF
!$OMP END PARALLEL
END SUBROUTINE
END MODULE