2 #if defined(__WITH_PETSC__)
3 #include <petsc/finclude/petscksp.h>
5 use petscksp,
only: petsc_comm_world, petscinitialize, petscfinalize, &
6 petsc_null_character, petsc_null_options
38 allocate (mpi_controller)
39 controller => mpi_controller
48 character(len=*),
parameter :: petsc_db_file =
'.petscrc'
49 logical(LGP) :: petsc_db_exists, wait_dbg, is_parallel_mode
59 #if defined(__WITH_PETSC__)
64 if (mpi_world%has_comm())
then
65 petsc_comm_world = mpi_world%comm
68 inquire (file=petsc_db_file, exist=petsc_db_exists)
69 if (.not. petsc_db_exists)
then
70 call petscinitialize(petsc_null_character, ierr)
73 call petscinitialize(petsc_db_file, ierr)
77 if (.not. mpi_world%has_comm())
then
78 call mpi_world%set_comm(petsc_comm_world)
81 call petscoptionshasname(petsc_null_options, petsc_null_character, &
82 '-wait_dbg', wait_dbg, ierr)
84 call petscoptionshasname(petsc_null_options, petsc_null_character, &
85 '-p', is_parallel_mode, ierr)
88 if (.not. mpi_world%has_comm())
then
91 call mpi_world%set_comm(mpi_comm_world)
97 call mpi_comm_size(mpi_world%comm,
nr_procs, ierr)
98 call mpi_comm_rank(mpi_world%comm,
proc_id, ierr)
101 if (wait_dbg)
call this%wait_for_debugger()
104 call this%RunControlType%start()
118 write (*, *)
'Hit enter to continue...'
121 call mpi_barrier(mpi_world%comm, ierr)
132 call this%virtual_data_mgr%router%finalize()
135 #if defined(__WITH_PETSC__)
138 call petscfinalize(ierr)
141 call mpi_finalize(ierr)
148 call this%RunControlType%finish()
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
177 call this%RunControlType%after_con_cr()
180 call remote_models%init()
184 if (vm%is_active .and. .not. vm%is_local)
then
186 call remote_models%push_back(vm%id)
189 call remote_exgs%init()
193 if (ve%is_active .and. .not. ve%is_local)
then
195 call remote_exgs%push_back(ve%id)
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)
205 allocate (remote_models_per_process(max_nr_remotes,
nr_procs))
206 remote_models_per_process = 0
209 do i = 1, remote_models%size
210 remote_models_per_process(i,
proc_id + 1) = remote_models%at(i)
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)
219 do j = 1, max_nr_remotes
220 id = remote_models_per_process(j, i)
224 if (vm%is_local)
then
227 call vm%rcv_ranks%push_back_unique(irank)
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)
239 allocate (remote_exgs_per_process(max_nr_remotes,
nr_procs))
240 remote_exgs_per_process = 0
243 do i = 1, remote_exgs%size
244 remote_exgs_per_process(i,
proc_id + 1) = remote_exgs%at(i)
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)
253 do j = 1, max_nr_remotes
254 id = remote_exgs_per_process(j, i)
258 if (ve%is_local)
then
261 call ve%rcv_ranks%push_back_unique(irank)
268 call remote_models%destroy()
269 call remote_exgs%destroy()
271 deallocate (remote_models_per_process)
272 deallocate (remote_exgs_per_process)
procedure(pstop_iface), pointer pstop_alternative
This module defines variable data types.
subroutine mpi_ctrl_finish(this)
subroutine wait_for_debugger(this)
class(runcontroltype) function, pointer, public create_mpi_run_control()
subroutine mpi_ctrl_after_con_cr(this)
Actions after creating connections.
subroutine mpi_ctrl_start(this)
type(mpiworldtype) function, pointer, public get_mpi_world()
subroutine, public mpi_stop(status)
subroutine, public check_mpi(mpi_error_code)
Check the MPI error code, report, and.
This module contains simulation variables.
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...