-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmpirecv.f90
More file actions
334 lines (241 loc) · 9.63 KB
/
Copy pathmpirecv.f90
File metadata and controls
334 lines (241 loc) · 9.63 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
submodule (mpimod) mpirecv
implicit none
contains
module procedure gather_recv2D_23
!! THIS SUBROUTINE GATHERS DATA FROM ALL WORKERS ONTO
!! A FULL-GRID ARRAY ON THE ROOT PROCESS (PRESUMABLY FOR
!! OUTPUT OR SOME ELECTRODYNAMIC CALCULATION, PERHAPS.
!!
!! THIS SUBROUTINE IS TO BE CALLED BY ROOT TO DO GATHER
!!
!! THIS VERSION WORKS ON 2D ARRAYS WHICH DO NOT INCLUDE ANY GHOST CELLS!!!!
integer :: lx1,lx2,lx3,lsp,lx2all,lx3all
integer :: iid
integer, dimension(4) :: inds
real(wp), dimension(1:size(paramtrim,1),1:size(paramtrim,2)) :: paramtmp
lx2=size(paramtrim,1) !note here that paramtrim does not have ghost cells
lx3=size(paramtrim,2)
!PATCH DATA TOGETHER FOR OUTPUT STARTING WITH ROOT'S SLAB
paramtrimall(1:lx2,1:lx3)=paramtrim !copy root's data into full-grid array
do iid=1,lid-1
call mpi_recv(paramtmp,lx2*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
inds=slabinds(iid,lx2,lx3)
paramtrimall(inds(1):inds(2),inds(3):inds(4))=paramtmp !note the exclusion of the ghost cells
end do
end procedure gather_recv2D_23
module procedure gather_recv3D_23
!! THIS SUBROUTINE GATHERS DATA FROM ALL WORKERS ONTO
!! A FULL-GRID ARRAY ON THE ROOT PROCESS (PRESUMABLY FOR
!! OUTPUT OR SOME ELECTRODYNAMIC CALCULATION, PERHAPS.
!!
!! THIS SUBROUTINE IS TO BE CALLED BY ROOT TO DO GATHER
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!! ANY GHOST CELLS!!!!
!! THIS VERION ALSO WORKS ON A PROCESS GRID
integer :: lx1,lx2,lx3,lx2all,lx3all
integer :: iid
integer, dimension(4) :: inds
real(wp), dimension(1:size(paramtrim,1),1:size(paramtrim,2),1:size(paramtrim,3)) :: paramtmp
!! buffer space for mpi receive, includes only x1 ghost cells
lx1=size(paramtrim,1)
lx2=size(paramtrim,2)
lx3=size(paramtrim,3)
!Originally the outer loop was over worker number, which cycles the 3rd dimension
!slower than 4th (backward from what would be most efficient memory access pattern)
!Since the gathering operation is root-limited probably, I'm guessing it's better
!to give root an efficient memory access pattern here, but I haven't tested this
!theory.
paramtrimall(:,1:lx2,1:lx3)=paramtrim(:,1:lx2,1:lx3) !store root's piece of data
do iid=1,lid-1 !must loop over all processes in the grid, don't enter loop if only root is present
call mpi_recv(paramtmp,lx1*lx2*lx3, & !note no ghost cells!!!
mpi_realprec,iid,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr) !recieve chunk of data into buffer
inds=slabinds(iid,lx2,lx3)
paramtrimall(1:lx1,inds(1):inds(2),inds(3):inds(4))=paramtmp !note the exclusion of the ghost cells
end do
end procedure gather_recv3D_23
module procedure gather_recv4D_23
!------------------------------------------------------------
!-------THIS SUBROUTINE GATHERS DATA FROM ALL WORKERS ONTO
!-------A FULL-GRID ARRAY ON THE ROOT PROCESS (PRESUMABLY FOR
!-------OUTPUT OR SOME ELECTRODYNAMIC CALCULATION, PERHAPS.
!-------
!-------THIS SUBROUTINE IS TO BE CALLED BY ROOT TO DO GATHER
!-------
!-------THIS VERSION WORKS ON 4D ARRAYS WHICH INCLUDE
!-------GHOST CELLS!
!------------------------------------------------------------
integer :: lx1,lx2,lx3,isp,lx2all,lx3all
integer :: iid
integer, dimension(4) :: inds
real(wp), dimension(-1:size(param,1)-2,1:size(param,2)-4,1:size(param,3)-4) :: paramtmp
!! buffer space for mpi receive, includes only x1 ghost cells
lx1=size(param,1)-4
lx2=size(param,2)-4
lx3=size(param,3)-4
!Originally the outer loop was over worker number, which cycles the 3rd dimension
!slower than 4th (backward from what would be most efficient memory access pattern)
!Since the gathering operation is root-limited probably, I'm guessing it's better
!to give root an efficient memory access pattern here, but I haven't tested this
!theory.
do isp=1,lsp
paramall(-1:lx1+2,1:lx2,1:lx3,isp)=param(-1:lx1+2,1:lx2,1:lx3,isp)
!! root records his own piece of the grid into full grid variable
do iid=1,lid-1 !must loop over all processes in the grid, don't enter loop if only root is present
call mpi_recv(paramtmp,(lx1+4)*lx2*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr) !recieve chunk of data into buffer
inds=slabinds(iid,lx2,lx3)
paramall(-1:lx1+2,inds(1):inds(2),inds(3):inds(4),isp)=paramtmp(-1:lx1+2,1:lx2,1:lx3) !note the inclusion of x1 ghost cells
end do
end do
end procedure gather_recv4D_23
module procedure bcast_recv1D_old3
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 1D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx
lx=size(param,1)-4
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(param,(lx+4), &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv1D_old3
module procedure bcast_recv1D_23_2
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 1D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx
integer :: iid
lx=size(param,1)-4
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(param,(lx+4), &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv1D_23_2
module procedure bcast_recv1D_23_3
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 1D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx
lx=size(param,1)-4
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(param,(lx+4), &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv1D_23_3
module procedure bcast_recv2D_23
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx2,lx3
lx2=size(paramtrim,1)
lx3=size(paramtrim,2)
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(paramtrim,lx2*lx3, &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv2D_23
module procedure bcast_recv3D_23
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx1,lx2,lx3
!> note here that paramtrim does not have ghost cells
lx1=size(paramtrim,1)
lx2=size(paramtrim,2)
lx3=size(paramtrim,3)
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(paramtrim,lx1*lx2*lx3, &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv3D_23
module procedure bcast_recv3D_x3i_23
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx1,lx2,lx3
!>note here that paramtrim does not have ghost cells
lx1=size(paramtrim,1)
lx2=size(paramtrim,2)
lx3=size(paramtrim,3)-1 ! `lx3` is an interfaced quantity
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(paramtrim,lx1*lx2*(lx3+1), &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv3D_x3i_23
module procedure bcast_recv3D_x2i_23
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx1,lx2,lx3
integer :: iid
!>note here that paramtrim does not have ghost cells
lx1=size(paramtrim,1)
lx2=size(paramtrim,2)-1 !x2 is the interfaced direction here
lx3=size(paramtrim,3)
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(paramtrim,lx1*(lx2+1)*lx3, &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv3D_x2i_23
module procedure bcast_recv3D_ghost_23
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!! GHOST CELLS!
integer :: lx1,lx2,lx3
!> note here that param has ghost cells
lx1=size(param,1)-4
lx2=size(param,2)-4
lx3=size(param,3)-4
!> WORKERS RECEIVE THE IC DATA FROM ROOT
call mpi_recv(param,(lx1+4)*(lx2+4)*(lx3+4), &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end procedure bcast_recv3D_ghost_23
module procedure bcast_recv4D_23
!! THIS SUBROUTINE RECEIVES BROADCAST DATA FROM A FULL
!! GRID ARRAY ON ROOT PROCESS TO WORKERS' SUB-GRID ARRAYS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY WORKERS TO DO A BROADCAST
!-------
!-------THIS VERSION WORKS ON 4D ARRAYS WHICH INCLUDE
!-------GHOST CELLS!
!------------------------------------------------------------
integer :: lx1,lx2,lx3,isp
real(wp), dimension(-1:size(param,1)-2,1:size(param,2)-4,1:size(param,3)-4) :: paramtmp
lx1=size(param,1)-4
lx2=size(param,2)-4
lx3=size(param,3)-4
!WORKERS RECEIVE THE IC DATA FROM ROOT
do isp=1,lsp
call mpi_recv(paramtmp,(lx1+4)*lx2*lx3, &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
param(-1:lx1+2,1:lx2,1:lx3,isp)=paramtmp(-1:lx1+2,1:lx2,1:lx3)
end do
end procedure bcast_recv4D_23
end submodule mpirecv