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
49 character(len=*),
parameter :: petsc_db_file =
'.petscrc'
50 logical(LGP) :: petsc_db_exists, wait_dbg, is_parallel_mode
60 #if defined(__WITH_PETSC__)
65 if (mpi_world%has_comm())
then
66 petsc_comm_world = mpi_world%comm
69 inquire (file=petsc_db_file, exist=petsc_db_exists)
70 if (.not. petsc_db_exists)
then
71 call petscinitialize(petsc_null_character, ierr)
74 call petscinitialize(petsc_db_file, ierr)
78 if (.not. mpi_world%has_comm())
then
79 call mpi_world%set_comm(petsc_comm_world)
82 call petscoptionshasname(petsc_null_options, petsc_null_character, &
83 '-wait_dbg', wait_dbg, ierr)
85 call petscoptionshasname(petsc_null_options, petsc_null_character, &
86 '-p', is_parallel_mode, ierr)
89 if (.not. mpi_world%has_comm())
then
92 call mpi_world%set_comm(mpi_comm_world)
98 call mpi_comm_size(mpi_world%comm,
nr_procs, ierr)
99 call mpi_comm_rank(mpi_world%comm,
proc_id, ierr)
102 if (wait_dbg)
call this%wait_for_debugger()
105 call this%RunControlType%start()
119 write (*, *)
'Hit enter to continue...'
122 call mpi_barrier(mpi_world%comm, ierr)
133 #if defined(__WITH_PETSC__)
136 call petscfinalize(ierr)
139 call mpi_finalize(ierr)
146 call this%RunControlType%finish()
162 integer(I4B) :: i, j, id, irank
163 integer(I4B) :: nr_models, nr_exgs, nr_remotes, max_nr_remotes
164 type(
stlvecint) :: remote_models, remote_exgs
165 integer(I4B),
dimension(:, :),
pointer :: remote_models_per_process
166 integer(I4B),
dimension(:, :),
pointer :: remote_exgs_per_process
175 call this%RunControlType%after_con_cr()
178 call remote_models%init()
182 if (vm%is_active .and. .not. vm%is_local)
then
184 call remote_models%push_back(vm%id)
187 call remote_exgs%init()
191 if (ve%is_active .and. .not. ve%is_local)
then
193 call remote_exgs%push_back(ve%id)
198 nr_remotes = remote_models%size
199 call mpi_allreduce(nr_remotes, max_nr_remotes, 1, mpi_integer, mpi_max, &
200 mpi_world%comm, ierr)
203 allocate (remote_models_per_process(max_nr_remotes,
nr_procs))
204 remote_models_per_process = 0
207 do i = 1, remote_models%size
208 remote_models_per_process(i,
proc_id + 1) = remote_models%at(i)
210 call mpi_allreduce(mpi_in_place, remote_models_per_process, &
211 max_nr_remotes *
nr_procs, mpi_integer, mpi_max, &
212 mpi_world%comm, ierr)
217 do j = 1, max_nr_remotes
218 id = remote_models_per_process(j, i)
222 if (vm%is_local)
then
225 call vm%rcv_ranks%push_back_unique(irank)
232 nr_remotes = remote_exgs%size
233 call mpi_allreduce(nr_remotes, max_nr_remotes, 1, mpi_integer, mpi_max, &
234 mpi_world%comm, ierr)
237 allocate (remote_exgs_per_process(max_nr_remotes,
nr_procs))
238 remote_exgs_per_process = 0
241 do i = 1, remote_exgs%size
242 remote_exgs_per_process(i,
proc_id + 1) = remote_exgs%at(i)
244 call mpi_allreduce(mpi_in_place, remote_exgs_per_process, &
245 max_nr_remotes *
nr_procs, mpi_integer, mpi_max, &
246 mpi_world%comm, ierr)
251 do j = 1, max_nr_remotes
252 id = remote_exgs_per_process(j, i)
256 if (ve%is_local)
then
259 call ve%rcv_ranks%push_back_unique(irank)
266 call remote_models%destroy()
267 call remote_exgs%destroy()
269 deallocate (remote_models_per_process)
270 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...