-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmpisend.f90
More file actions
322 lines (225 loc) · 8.85 KB
/
Copy pathmpisend.f90
File metadata and controls
322 lines (225 loc) · 8.85 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
subroutine gather_send2D_3(paramtrim,tag)
!------------------------------------------------------------
!-------THIS SUBROUTINE GATHERS DATA FROM ALL WORKERS ONTO
!-------A FULL-GRID ARRAY ON THE ROOT PROCESS (PRESUMABLY FOR
!-------OUTPUT OR SOME ELECTRODYNAMIC CALCULATION, PERHAPS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY WORKERS TO DO GATHER
!-------
!-------THIS VERSION WORKS ON 2D ARRAYS WHICH DO NOT INCLUDE
!-------ANY GHOST CELLS!!!!
!------------------------------------------------------------
real(wp), dimension(:,:), intent(in) :: paramtrim
integer, intent(in) :: tag
integer :: lx2,lx3
lx2=size(paramtrim,1) !note here that paramtrim does not have ghost cells
lx3=size(paramtrim,2)
call mpi_send(paramtrim,lx2*lx3,mpi_realprec,0,tag,MPI_COMM_WORLD,ierr)
end subroutine gather_send2D_3
subroutine gather_send3D_3(paramtrim,tag)
!------------------------------------------------------------
!-------THIS SUBROUTINE GATHERS DATA FROM ALL WORKERS ONTO
!-------A FULL-GRID ARRAY ON THE ROOT PROCESS (PRESUMABLY FOR
!-------OUTPUT OR SOME ELECTRODYNAMIC CALCULATION, PERHAPS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY WORKERS TO DO GATHER
!-------
!-------THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!-------ANY GHOST CELLS!!!!
!------------------------------------------------------------
real(wp), dimension(:,:,:), intent(in) :: paramtrim
integer, intent(in) :: tag
integer :: lx1,lx2,lx3
lx1=size(paramtrim,1) !note here that paramtrim does not have ghost cells
lx2=size(paramtrim,2)
lx3=size(paramtrim,3)
call mpi_send(paramtrim,lx1*lx2*lx3,mpi_realprec,0,tag,MPI_COMM_WORLD,ierr)
end subroutine gather_send3D_3
subroutine gather_send4D_3(param,tag)
!------------------------------------------------------------
!-------THIS SUBROUTINE GATHERS DATA FROM ALL WORKERS ONTO
!-------A FULL-GRID ARRAY ON THE ROOT PROCESS (PRESUMABLY FOR
!-------OUTPUT OR SOME ELECTRODYNAMIC CALCULATION, PERHAPS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY WORKERS TO DO GATHER
!-------
!-------THIS VERSION WORKS ON 4D ARRAYS WHICH INCLUDE
!-------GHOST CELLS!
!------------------------------------------------------------
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: param
integer, intent(in) :: tag
integer :: lx1,lx2,lx3,isp
lx1=size(param,1)-4
lx2=size(param,2)-4
lx3=size(param,3)-4
do isp=1,lsp
call mpi_send(param(:,:,1:lx3,isp),(lx1+4)*(lx2+4)*lx3,mpi_realprec,0,tag,MPI_COMM_WORLD,ierr)
end do
end subroutine gather_send4D_3
subroutine bcast_send1D_3(paramall,tag,param)
!------------------------------------------------------------
!-------BROADCASTS MPI DIMENSION VARIABLES TO WORKERS. NOTE THAT
!-------WE'VE ELECTED TO NOT USE THE GENERAL BROADCAST ROUTINES FOR
!-------SINCE THESE OPERATIONS REQUIRE A LOT OF SPECIAL CASING FOR
!-------THE SIZES OF THE VARIABLES TO BE SENT
!-------
!-------SUBROUTINE IS TO BE CALLED BY ROOT TO DO A BROADCAST
!-------
!-------THIS VERSION WORKS ON 1D ARRAYS
!------------------------------------------------------------
real(wp), dimension(-1:), intent(in) :: paramall
integer, intent(in) :: tag
real(wp), dimension(-1:), intent(out) :: param
integer :: lx,lxall !local sizes
integer :: iid,islstart,islfin
lxall=size(paramall,1)-4
lx=size(param,1)-4
do iid=1,lid-1
islstart=iid*lx+1
islfin=islstart+lx-1
call mpi_send(paramall(islstart-2:islfin+2),(lx+4), &
mpi_realprec,iid,tag,MPI_COMM_WORLD,ierr)
end do
param=paramall(-1:lx+2)
end subroutine bcast_send1D_3
subroutine bcast_send2D_3(paramtrimall,tag,paramtrim)
!------------------------------------------------------------
!-------THIS SUBROUTINE BROADCASTS DATA FROM A FULL GRID ARRAY
!-------ON ROOT PROCESS TO ALL WORKERS' SUB-GRID ARRAYS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY ROOT TO DO A BROADCAST
!-------
!-------THIS VERSION WORKS ON 2D ARRAYS WHICH DO NOT INCLUDE
!-------GHOST CELLS!
!------------------------------------------------------------
real(wp), dimension(:,:), intent(in) :: paramtrimall
integer, intent(in) :: tag
real(wp), dimension(:,:), intent(out) :: paramtrim
integer :: lx2,lx3
integer :: iid,islstart,islfin
lx2=size(paramtrim,1) !assume this is an array which has been 'flattened' along the 1-dimension
lx3=size(paramtrim,2)
!ROOT BROADCASTS IC DATA TO WORKERS
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_send(paramtrimall(:,islstart:islfin),lx2*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,ierr)
end do
!ROOT TAKES A SLAB OF DATA
paramtrim=paramtrimall(:,1:lx3)
end subroutine bcast_send2D_3
subroutine bcast_send3D_3(paramtrimall,tag,paramtrim)
!------------------------------------------------------------
!-------THIS SUBROUTINE BROADCASTS DATA FROM A FULL GRID ARRAY
!-------ON ROOT PROCESS TO ALL WORKERS' SUB-GRID ARRAYS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY ROOT TO DO A BROADCAST
!-------
!-------THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!-------GHOST CELLS!
!-------
!-------ALSO NOTE THAT IF THE ARRAY SIZE (DIM 3) DOES NOT CORRESPOND
!-------TO THE SIZE OF THE SYSTEM IN THE X3-DIRECTION, THEN
!-------THE SLAB CALCULATIONS FOR WORKERS WILL BE OFF.
!------------------------------------------------------------
real(wp), dimension(:,:,:), intent(in) :: paramtrimall
integer, intent(in) :: tag
real(wp), dimension(:,:,:), intent(out) :: paramtrim
integer :: lx1,lx2,lx3
integer :: iid,islstart,islfin
lx1=size(paramtrim,1) !note here that paramtrim does not have ghost cells
lx2=size(paramtrim,2)
lx3=size(paramtrim,3)
!> ROOT BROADCASTS IC DATA TO WORKERS
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_send(paramtrimall(:,:,islstart:islfin),lx1*lx2*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,ierr)
end do
!> ROOT TAKES A SLAB OF DATA
paramtrim=paramtrimall(:,:,1:lx3)
end subroutine bcast_send3D_3
subroutine bcast_send3D_x3i_3(paramtrimall,tag,paramtrim)
!------------------------------------------------------------
!-------THIS SUBROUTINE BROADCASTS DATA FROM A FULL GRID ARRAY
!-------ON ROOT PROCESS TO ALL WORKERS' SUB-GRID ARRAYS.
!-------
!-------SUBROUTINE IS TO BE CALLED BY ROOT TO DO A BROADCAST
!-------
!-------THIS VERSION WORKS ON 3D ARRAYS WHICH DO NOT INCLUDE
!-------GHOST CELLS, BUT ARE X3 INTERFACE QUANITTIES
!------------------------------------------------------------
real(wp), dimension(:,:,:), intent(in) :: paramtrimall
integer, intent(in) :: tag
real(wp), dimension(:,:,:), intent(out) :: paramtrim
integer :: lx1,lx2,lx3
integer :: iid,islstart,islfin
lx1=size(paramtrim,1) !note here that paramtrim does not have ghost cells
lx2=size(paramtrim,2)
lx3=size(paramtrim,3)-1 !note that we are interpreting input as an x3i quantity meaning that it has size lx3+1
!ROOT BROADCASTS IC DATA TO WORKERS
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_send(paramtrimall(:,:,islstart:islfin+1),lx1*lx2*(lx3+1), &
mpi_realprec,iid,tag,MPI_COMM_WORLD,ierr) !note the +1 since thes are interfact quantities (and need to overlap b/t workers)
end do
!ROOT TAKES A SLAB OF DATA
paramtrim=paramtrimall(:,:,1:lx3+1)
end subroutine bcast_send3D_x3i_3
subroutine bcast_send3D_ghost_3(paramall,tag,param)
!! THIS SUBROUTINE BROADCASTS DATA FROM A FULL GRID ARRAY
!!ON ROOT PROCESS TO ALL WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY ROOT TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 3D ARRAYS WHICH INCLUDE GHOST CELLS
real(wp), dimension(-1:,-1:,-1:), intent(in) :: paramall
integer, intent(in) :: tag
real(wp), dimension(-1:,-1:,-1:), intent(out) :: param
integer :: lx1,lx2,lx3
integer :: iid,islstart,islfin
!> note here that param has ghost cells
lx1=size(param,1)-4
lx2=size(param,2)-4
lx3=size(param,3)-4
!> ROOT BROADCASTS IC DATA TO WORKERS
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_send(paramall(:,:,islstart-2:islfin+2),(lx1+4)*(lx2+4)*(lx3+4), &
mpi_realprec,iid,tag,MPI_COMM_WORLD,ierr)
end do
!> ROOT TAKES A SLAB OF DATA
param=paramall(:,:,-1:lx3+2)
end subroutine bcast_send3D_ghost_3
subroutine bcast_send4D_3(paramall,tag,param)
!! THIS SUBROUTINE BROADCASTS DATA FROM A FULL GRID ARRAY
!! ON ROOT PROCESS TO ALL WORKERS' SUB-GRID ARRAYS.
!!
!! SUBROUTINE IS TO BE CALLED BY ROOT TO DO A BROADCAST
!!
!! THIS VERSION WORKS ON 4D ARRAYS WHICH INCLUDE
!! GHOST CELLS!
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: paramall
integer, intent(in) :: tag
real(wp), dimension(-1:,-1:,-1:,:), intent(out) :: param
integer :: lx1,lx2,lx3,isp
integer :: iid,islstart,islfin
lx1=size(param,1)-4
lx2=size(param,2)-4
lx3=size(param,3)-4
!> ROOT BROADCASTS IC DATA TO WORKERS
do isp=1,lsp
param(:,:,:,isp)=paramall(:,:,-1:lx3+2,isp)
!! roots part of the data
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_send(paramall(:,:,islstart-2:islfin+2,isp),(lx1+4)*(lx2+4)*(lx3+4), &
mpi_realprec,iid,tag,MPI_COMM_WORLD,ierr)
end do
end do
end subroutine bcast_send4D_3