20 character(len=LENMEMPATH) :: memory_path
21 integer(I4B),
pointer :: nr_models
22 integer(I4B),
dimension(:),
pointer,
contiguous :: load_mask => null()
23 integer(I4B),
dimension(:),
pointer,
contiguous :: model_ranks => null()
59 character(len=LENMEMPATH) :: input_mempath
60 integer(I4B),
pointer :: nmod
65 call mem_setptr(nmod,
'NUMMODELS', input_mempath)
67 call mem_allocate(this%nr_models,
'NUMMODELS', this%memory_path)
83 integer(I4B),
dimension(:),
pointer :: load_mask
85 if (.not.
associated(this%load_mask))
then
86 call this%create_load_mask()
88 load_mask => this%load_mask
97 integer(I4B),
dimension(:),
pointer :: model_ranks => null()
100 call mem_allocate(this%load_mask, this%nr_models,
'LOADMASK', &
105 model_ranks => this%get_load_balance()
108 do m_id = 1, this%nr_models
109 if (model_ranks(m_id) ==
proc_id)
then
110 this%load_mask(m_id) = 1
112 this%load_mask(m_id) = 0
122 integer(I4B),
dimension(:),
pointer :: mranks
124 integer(I4B) :: isize
125 character(len=LENMEMPATH) :: hpc_mempath
128 if (
associated(this%model_ranks))
then
129 mranks => this%model_ranks
133 call mem_allocate(this%model_ranks, this%nr_models,
'MODELRANKS', &
138 call get_isize(
'MNAME', hpc_mempath, isize)
143 write (
warnmsg, *)
"Ignoring PARTITIONS block in HPC file when "// &
144 "running a serial process"
151 call this%set_load_balance_from_input()
153 call this%validate_load_balance()
162 call this%set_load_balance_default()
166 mranks => this%model_ranks
175 character(len=LENMEMPATH) :: simnam_mempath, hpc_mempath
176 character(len=LENMODELNAME) :: model_name
179 integer(I4B),
dimension(:),
contiguous,
pointer :: mranks_hpc
180 integer(I4B) :: i, model_idx
181 integer(I4B) :: target_rank
182 integer(I4B),
dimension(:),
allocatable :: rank_used
184 character(len=LINELENGTH) :: hpc_filename
187 this%model_ranks = -1
192 call mem_setptr(mnames,
'MNAME', simnam_mempath)
193 call mem_setptr(mnames_hpc,
'MNAME', hpc_mempath)
194 call mem_setptr(mranks_hpc,
'MRANK', hpc_mempath)
195 call mem_setptr(hpc_names,
'HPC6_FILENAME', simnam_mempath)
198 hpc_filename = hpc_names(1)
201 do i = 1,
size(mnames_hpc)
202 if (
ifind(mnames, mnames_hpc(i)) == -1)
then
203 model_name = mnames_hpc(i)
204 write (
errmsg, *)
"HPC input error: undefined model name (", &
205 trim(model_name),
")"
210 do i = 1,
size(mranks_hpc)
211 target_rank = mranks_hpc(i)
212 if (target_rank < 0 .or. target_rank >
nr_procs - 1)
then
213 model_name = mnames_hpc(i)
214 write (
errmsg,
'(a,i0,2a)')
"HPC input error: invalid target rank (", &
215 target_rank,
") for model ", trim(model_name)
224 do i = 1,
size(mnames_hpc)
225 model_idx =
ifind(mnames, mnames_hpc(i))
226 this%model_ranks(model_idx) = mranks_hpc(i)
230 do i = 1,
size(this%model_ranks)
231 if (this%model_ranks(i) == -1)
then
232 model_name = mnames(i)
233 write (
errmsg,
'(2a)')
"HPC input error: no target rank for model ", &
245 do i = 1,
size(this%model_ranks)
246 if (this%model_ranks(i) >= 0 .and. this%model_ranks(i) <
nr_procs)
then
247 rank_used(this%model_ranks(i) + 1) = 1
250 do i = 1,
size(rank_used)
251 if (rank_used(i) == 0)
then
252 write (
errmsg,
'(a,i0,a)')
"HPC input error: rank ", i - 1, &
253 " has no models assigned"
257 deallocate (rank_used)
270 integer(I4B) :: im, imm, ie, ip, cnt
271 integer(I4B) :: nr_models, nr_gwf_models
272 integer(I4B) :: nr_exchanges
273 integer(I4B) :: min_per_proc, nr_left
275 integer(I4B),
dimension(:),
allocatable :: nr_models_proc
276 character(len=LENPACKAGETYPE) :: model_type_str
277 character(len=LENMEMPATH) :: input_mempath
293 call mem_setptr(mtypes,
'MTYPE', input_mempath)
294 call mem_setptr(mnames,
'MNAME', input_mempath)
295 call mem_setptr(etypes,
'EXGTYPE', input_mempath)
296 call mem_setptr(emnames_a,
'EXGMNAMEA', input_mempath)
297 call mem_setptr(emnames_b,
'EXGMNAMEB', input_mempath)
300 nr_models =
size(mnames)
303 if (mtypes(im) ==
'GWF6')
then
304 nr_gwf_models = nr_gwf_models + 1
307 if (mtypes(im) ==
'GWF6' .or. &
308 mtypes(im) ==
'GWT6' .or. &
309 mtypes(im) ==
'GWE6')
then
313 model_type_str = mtypes(im)
314 write (
errmsg, *)
'Model type ', model_type_str, &
315 ' not supported in parallel mode.'
321 min_per_proc = nr_gwf_models /
nr_procs
322 nr_left = nr_gwf_models -
nr_procs * min_per_proc
326 nr_models_proc(ip) = min_per_proc
327 if (rank < nr_left)
then
328 nr_models_proc(ip) = nr_models_proc(ip) + 1
335 if (mtypes(im) ==
'GWF6')
then
336 if (nr_models_proc(rank + 1) == 0)
then
339 this%model_ranks(im) = rank
340 nr_models_proc(rank + 1) = nr_models_proc(rank + 1) - 1
345 nr_exchanges =
size(etypes)
347 if (mtypes(im) ==
'GWT6')
then
350 do ie = 1, nr_exchanges
351 if (etypes(ie) ==
'GWF6-GWT6' .and. mnames(im) == emnames_b(ie))
then
353 do imm = 1, nr_models
354 if (mnames(imm) == emnames_a(ie))
then
355 rank = this%model_ranks(imm)
359 this%model_ranks(im) = rank
364 else if (mtypes(im) ==
'GWE6')
then
365 do ie = 1, nr_exchanges
366 if (etypes(ie) ==
'GWF6-GWE6' .and. mnames(im) == emnames_b(ie))
then
368 do imm = 1, nr_models
369 if (mnames(imm) == emnames_a(ie))
then
370 rank = this%model_ranks(imm)
374 this%model_ranks(im) = rank
385 deallocate (nr_models_proc)
393 character(len=LENMEMPATH) :: input_mempath
407 integer(I4B) :: idx_a, idx_b
408 integer(I4B) :: rank_a, rank_b
409 integer(I4B) :: nr_exchanges
410 character(len=LINELENGTH) :: hpc_filename
411 character(len=LENMODELNAME) :: name_a, name_b
412 character(len=LINELENGTH) :: exg_type
416 call mem_setptr(mtypes,
'MTYPE', input_mempath)
417 call mem_setptr(mnames,
'MNAME', input_mempath)
418 call mem_setptr(etypes,
'EXGTYPE', input_mempath)
419 call mem_setptr(emnames_a,
'EXGMNAMEA', input_mempath)
420 call mem_setptr(emnames_b,
'EXGMNAMEB', input_mempath)
421 call mem_setptr(hpc_names,
'HPC6_FILENAME', input_mempath)
424 hpc_filename = hpc_names(1)
426 nr_exchanges =
size(etypes)
429 do ie = 1, nr_exchanges
430 if (etypes(ie) ==
'GWF6-GWT6' .or. etypes(ie) ==
'GWF6-GWE6')
then
431 idx_a =
ifind(mnames, emnames_a(ie))
432 idx_b =
ifind(mnames, emnames_b(ie))
433 rank_a = this%model_ranks(idx_a)
434 rank_b = this%model_ranks(idx_b)
435 if (rank_a /= rank_b)
then
436 name_a = emnames_a(ie)
437 name_b = emnames_b(ie)
438 exg_type = etypes(ie)
439 write (
errmsg,
'(7a)')
"HPC input error: models ", &
440 trim(name_a),
" and ", trim(name_b),
" with a ", &
441 trim(exg_type),
" coupling have to be assigned to the same rank"
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
integer(i4b), parameter lenmodelname
maximum length of the model name
integer(i4b), parameter lenpackagetype
maximum length of a package type (DIS6, SFR6, CSUB6, etc.)
integer(i4b), parameter lenmempath
maximum length of the memory path
subroutine set_load_balance_from_input(this)
Load load balance from the input configuration.
subroutine validate_load_balance(this)
Check validity of load balance configuration.
subroutine create_load_mask(this)
Create a load mask for IDM from the load balance array.
class(distributedsimtype) function, pointer, public get_dsim()
Get pointer to the distributed simulation object.
integer(i4b) function, dimension(:), pointer get_load_mask(this)
Return pointer to the load mask for models.
subroutine create(this)
Create the distributed simulation object from the simulation input ctx.
class(distributedsimtype), pointer, private dist_sim
subroutine set_load_balance_default(this)
Distribute the models over the available processes in a parallel run. Expects an array sized.
integer(i4b) function, dimension(:), pointer get_load_balance(this)
Get the model load balance for the simulation.
subroutine destroy(this)
clean up
This module defines variable data types.
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public mem_print_detailed(iout)
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
This module contains simulation methods.
subroutine, public store_warning(msg, substring)
Store warning message.
subroutine, public store_error(msg, terminate)
Store an error message.
integer(i4b) function, public count_errors()
Return number of errors.
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
character(len=linelength) idm_context
character(len=maxcharlen) warnmsg
warning message string
This class is used to store a single deferred-length character string. It was designed to work in an ...