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
39 allocate (mpi_controller)
40 controller => mpi_controller
47 integer(I4B) :: tmr_init_par
52 character(len=*),
parameter :: petsc_db_file =
'.petscrc'
53 logical(LGP) :: petsc_db_exists, wait_dbg, is_parallel_mode
58 call g_prof%start(
"Initialize MPI and PETSc", tmr_init_par)
67 #if defined(__WITH_PETSC__)
72 if (mpi_world%has_comm())
then
73 petsc_comm_world = mpi_world%comm
76 inquire (file=petsc_db_file, exist=petsc_db_exists)
77 if (.not. petsc_db_exists)
then
78 call petscinitialize(petsc_null_character, ierr)
81 call petscinitialize(petsc_db_file, ierr)
85 if (.not. mpi_world%has_comm())
then
86 call mpi_world%set_comm(petsc_comm_world)
89 call petscoptionshasname(petsc_null_options, petsc_null_character, &
90 '-wait_dbg', wait_dbg, ierr)
92 call petscoptionshasname(petsc_null_options, petsc_null_character, &
93 '-p', is_parallel_mode, ierr)
96 if (.not. mpi_world%has_comm())
then
99 call mpi_world%set_comm(mpi_comm_world)
103 call mpi_world%init()
105 call mpi_comm_size(mpi_world%comm,
nr_procs, ierr)
106 call mpi_comm_rank(mpi_world%comm,
proc_id, ierr)
109 if (wait_dbg)
call this%wait_for_debugger()
112 call g_prof%stop(tmr_init_par)
115 call this%RunControlType%start()
129 write (*, *)
'Hit enter to continue...'
132 call mpi_barrier(mpi_world%comm, ierr)
141 integer(I4B) :: tmr_final_par
145 call g_prof%start(
"Finalize MPI and PETSc", tmr_final_par)
148 call this%virtual_data_mgr%router%finalize()
151 #if defined(__WITH_PETSC__)
154 call petscfinalize(ierr)
157 call mpi_finalize(ierr)
163 call g_prof%stop(tmr_final_par)
166 call this%RunControlType%finish()
182 integer(I4B) :: i, j, id, irank
183 integer(I4B) :: nr_models, nr_exgs, nr_remotes, max_nr_remotes
184 type(
stlvecint) :: remote_models, remote_exgs
185 integer(I4B),
dimension(:, :),
pointer :: remote_models_per_process
186 integer(I4B),
dimension(:, :),
pointer :: remote_exgs_per_process
195 call this%RunControlType%after_con_cr()
198 call remote_models%init()
202 if (vm%is_active .and. .not. vm%is_local)
then
204 call remote_models%push_back(vm%id)
207 call remote_exgs%init()
211 if (ve%is_active .and. .not. ve%is_local)
then
213 call remote_exgs%push_back(ve%id)
218 nr_remotes = remote_models%size
219 call mpi_allreduce(nr_remotes, max_nr_remotes, 1, mpi_integer, mpi_max, &
220 mpi_world%comm, ierr)
223 allocate (remote_models_per_process(max_nr_remotes,
nr_procs))
224 remote_models_per_process = 0
227 do i = 1, remote_models%size
228 remote_models_per_process(i,
proc_id + 1) = remote_models%at(i)
230 call mpi_allreduce(mpi_in_place, remote_models_per_process, &
231 max_nr_remotes *
nr_procs, mpi_integer, mpi_max, &
232 mpi_world%comm, ierr)
237 do j = 1, max_nr_remotes
238 id = remote_models_per_process(j, i)
242 if (vm%is_local)
then
245 call vm%rcv_ranks%push_back_unique(irank)
252 nr_remotes = remote_exgs%size
253 call mpi_allreduce(nr_remotes, max_nr_remotes, 1, mpi_integer, mpi_max, &
254 mpi_world%comm, ierr)
257 allocate (remote_exgs_per_process(max_nr_remotes,
nr_procs))
258 remote_exgs_per_process = 0
261 do i = 1, remote_exgs%size
262 remote_exgs_per_process(i,
proc_id + 1) = remote_exgs%at(i)
264 call mpi_allreduce(mpi_in_place, remote_exgs_per_process, &
265 max_nr_remotes *
nr_procs, mpi_integer, mpi_max, &
266 mpi_world%comm, ierr)
271 do j = 1, max_nr_remotes
272 id = remote_exgs_per_process(j, i)
276 if (ve%is_local)
then
279 call ve%rcv_ranks%push_back_unique(irank)
286 call remote_models%destroy()
287 call remote_exgs%destroy()
289 deallocate (remote_models_per_process)
290 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.
type(profilertype), public g_prof
the global timer object (to reduce trivial lines of code)
subroutine start(this, title, section_id)
Start section timing, add when not exist yet (i.e. when id < 1)
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...