162 class(MpiRunControlType) :: this
163
164 integer(I4B) :: i, j, id, irank
165 integer(I4B) :: nr_models, nr_exgs, nr_remotes, max_nr_remotes
166 type(STLVecInt) :: remote_models, remote_exgs
167 integer(I4B), dimension(:, :), pointer :: remote_models_per_process
168 integer(I4B), dimension(:, :), pointer :: remote_exgs_per_process
169 class(VirtualModelType), pointer :: vm
170 class(VirtualExchangeType), pointer :: ve
171 type(MpiWorldType), pointer :: mpi_world
172 integer :: ierr
173
174 mpi_world => get_mpi_world()
175
176
177 call this%RunControlType%after_con_cr()
178
179
180 call remote_models%init()
182 do i = 1, nr_models
184 if (vm%is_active .and. .not. vm%is_local) then
185
186 call remote_models%push_back(vm%id)
187 end if
188 end do
189 call remote_exgs%init()
191 do i = 1, nr_exgs
193 if (ve%is_active .and. .not. ve%is_local) then
194
195 call remote_exgs%push_back(ve%id)
196 end if
197 end do
198
199
200 nr_remotes = remote_models%size
201 call mpi_allreduce(nr_remotes, max_nr_remotes, 1, mpi_integer, mpi_max, &
202 mpi_world%comm, ierr)
203 call check_mpi(ierr)
204
205 allocate (remote_models_per_process(max_nr_remotes, nr_procs))
206 remote_models_per_process = 0
207
208
209 do i = 1, remote_models%size
210 remote_models_per_process(i, proc_id + 1) = remote_models%at(i)
211 end do
212 call mpi_allreduce(mpi_in_place, remote_models_per_process, &
213 max_nr_remotes * nr_procs, mpi_integer, mpi_max, &
214 mpi_world%comm, ierr)
215 call check_mpi(ierr)
216
217
218 do i = 1, nr_procs
219 do j = 1, max_nr_remotes
220 id = remote_models_per_process(j, i)
221 if (id > 0) then
222
224 if (vm%is_local) then
225
226 irank = i - 1
227 call vm%rcv_ranks%push_back_unique(irank)
228 end if
229 end if
230 end do
231 end do
232
233
234 nr_remotes = remote_exgs%size
235 call mpi_allreduce(nr_remotes, max_nr_remotes, 1, mpi_integer, mpi_max, &
236 mpi_world%comm, ierr)
237 call check_mpi(ierr)
238
239 allocate (remote_exgs_per_process(max_nr_remotes, nr_procs))
240 remote_exgs_per_process = 0
241
242
243 do i = 1, remote_exgs%size
244 remote_exgs_per_process(i, proc_id + 1) = remote_exgs%at(i)
245 end do
246 call mpi_allreduce(mpi_in_place, remote_exgs_per_process, &
247 max_nr_remotes * nr_procs, mpi_integer, mpi_max, &
248 mpi_world%comm, ierr)
249 call check_mpi(ierr)
250
251
252 do i = 1, nr_procs
253 do j = 1, max_nr_remotes
254 id = remote_exgs_per_process(j, i)
255 if (id > 0) then
256
258 if (ve%is_local) then
259
260 irank = i - 1
261 call ve%rcv_ranks%push_back_unique(irank)
262 end if
263 end if
264 end do
265 end do
266
267
268 call remote_models%destroy()
269 call remote_exgs%destroy()
270
271 deallocate (remote_models_per_process)
272 deallocate (remote_exgs_per_process)
273
type(listtype), public virtual_model_list
type(listtype), public virtual_exchange_list
class(virtualexchangetype) function, pointer, public get_virtual_exchange_from_list(list, idx)
class(virtualexchangetype) function, pointer, public get_virtual_exchange(exg_id)
Returns a virtual exchange with the specified id.
class(virtualmodeltype) function, pointer, public get_virtual_model_from_list(model_list, idx)
The Virtual Exchange is based on two Virtual Models and is therefore not always strictly local or rem...