-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmpirecv.f90
More file actions
262 lines (184 loc) · 6.97 KB
/
Copy pathmpirecv.f90
File metadata and controls
262 lines (184 loc) · 6.97 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
module procedure gather_recv2D_3
!! 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!!!!
real(wp), dimension(:,:), intent(in) :: paramtrim
integer, intent(in) :: tag
real(wp), dimension(:,:), intent(out) :: paramtrimall
integer :: lx1,lx2,lx3,isp,lsp
integer :: iid,islstart,islfin
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:lx3)=paramtrim !copy root's data into full-grid array
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_recv(paramtrimall(:,islstart:islfin),lx2*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end do
end procedure gather_recv2D_3
subroutine gather_recv4D_3(param,tag,paramall)
!------------------------------------------------------------
!-------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!
!------------------------------------------------------------
real(wp), dimension(-1:,-1:,-1:,:), intent(in) :: param
integer, intent(in) :: tag
real(wp), dimension(-1:,-1:,-1:,:), intent(out) :: paramall
integer :: lx1,lx2,lx3,isp
integer :: iid,islstart,islfin
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:lx3,isp)=param(:,:,1:lx3,isp)
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_recv(paramall(:,:,islstart:islfin,isp),(lx1+4)*(lx2+4)*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end do
end do
end subroutine gather_recv4D_3
subroutine bcast_recv3D_x3i_3(paramtrim,tag)
!! 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!
real(wp), dimension(:,:,:), intent(out) :: paramtrim
integer, intent(in) :: tag
integer :: lx1,lx2,lx3
integer :: iid
!>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 x3i 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 subroutine bcast_recv3D_x3i_3
subroutine bcast_recv3D_ghost_3(param,tag)
!! 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!
real(wp), dimension(-1:,-1:,-1:), intent(out) :: param
integer, intent(in) :: tag
integer :: lx1,lx2,lx3
integer :: iid
!> 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 subroutine bcast_recv3D_ghost_3
subroutine bcast_recv4D_3(param,tag)
!! 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!
!------------------------------------------------------------
real(wp), dimension(-1:,-1:,-1:,:), intent(out) :: 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
!WORKERS RECEIVE THE IC DATA FROM ROOT
do isp=1,lsp
call mpi_recv(param(:,:,:,isp),(lx1+4)*(lx2+4)*(lx3+4), &
mpi_realprec,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end do
end subroutine bcast_recv4D_3
subroutine bcast_recv2D_3(paramtrim,tag)
!! 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!
real(wp), dimension(:,:), intent(out) :: paramtrim
integer, intent(in) :: tag
integer :: lx2,lx3
integer :: iid
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 subroutine bcast_recv2D_3
subroutine bcast_recv3D_3(paramtrim,tag)
!! 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!
real(wp), dimension(:,:,:), intent(out) :: paramtrim
integer, intent(in) :: tag
integer :: lx1,lx2,lx3
integer :: iid
!> 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 subroutine bcast_recv3D_3
subroutine gather_recv3D_3(paramtrim,tag,paramtrimall)
!! 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!!!!
real(wp), dimension(:,:,:), intent(in) :: paramtrim
integer, intent(in) :: tag
real(wp), dimension(:,:,:), intent(out) :: paramtrimall
integer :: lx1,lx2,lx3,isp,lsp
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)
!PATCH DATA TOGETHER FOR OUTPUT STARTING WITH ROOT'S SLAB
paramtrimall(:,:,1:lx3)=paramtrim !copy root's data into full-grid array
do iid=1,lid-1
islstart=iid*lx3+1
islfin=islstart+lx3-1
call mpi_recv(paramtrimall(:,:,islstart:islfin),lx1*lx2*lx3, &
mpi_realprec,iid,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
end do
end subroutine gather_recv3D_3