22 character(len=LENMEMPATH) :: memory_path
23 integer(I4B),
pointer :: nr_models
24 integer(I4B),
dimension(:),
pointer,
contiguous :: load_mask => null()
25 integer(I4B),
dimension(:),
pointer,
contiguous :: model_ranks => null()
26 logical(LGP),
pointer :: print_ptable
63 character(len=LENMEMPATH) :: input_mempath
64 integer(I4B),
pointer :: nmod
69 call mem_setptr(nmod,
'NUMMODELS', input_mempath)
71 call mem_allocate(this%nr_models,
'NUMMODELS', this%memory_path)
74 call mem_allocate(this%print_ptable,
'PRINT_PTABLE', this%memory_path)
75 this%print_ptable = .false.
90 integer(I4B),
dimension(:),
pointer :: load_mask
92 if (.not.
associated(this%load_mask))
then
93 call this%create_load_mask()
95 load_mask => this%load_mask
104 integer(I4B),
dimension(:),
pointer :: model_ranks => null()
107 call mem_allocate(this%load_mask, this%nr_models,
'LOADMASK', &
112 model_ranks => this%get_load_balance()
115 do m_id = 1, this%nr_models
116 if (model_ranks(m_id) ==
proc_id)
then
117 this%load_mask(m_id) = 1
119 this%load_mask(m_id) = 0
131 integer(I4B),
dimension(:),
pointer :: mranks
133 integer(I4B) :: isize
134 logical(LGP) :: hpc6_present, partitions_present
135 character(len=LENMEMPATH) :: simnam_mempath, hpc_mempath
139 if (
associated(this%model_ranks))
then
140 mranks => this%model_ranks
144 call mem_allocate(this%model_ranks, this%nr_models,
'MODELRANKS', &
149 call get_isize(
'HPC6_FILENAME', simnam_mempath, isize)
150 hpc6_present = isize > 0
153 if (simulation_mode ==
'SEQUENTIAL')
then
154 if (hpc6_present)
then
155 write (warnmsg, *)
"Ignoring PARTITIONS block in HPC file when "// &
156 "running a serial process"
162 mranks => this%model_ranks
167 write (
iout,
'(/1x,a)')
'PROCESSING HPC DATA'
171 call mem_set_value(this%print_ptable,
'PRINT_TABLE', hpc_mempath, &
174 call get_isize(
'MNAME', hpc_mempath, isize)
175 partitions_present = isize > 0
178 if (partitions_present)
then
180 call this%set_load_balance_from_input()
181 call this%validate_load_balance()
182 write (
iout,
'(1x,a)')
'Read partition data from HPC file'
185 call this%set_load_balance_default()
186 write (
iout,
'(1x,a)')
'Generate default partition data'
189 mranks => this%model_ranks
192 if (this%print_ptable)
then
193 call this%print_load_balance()
196 write (
iout,
'(1x,a)')
'END OF HPC DATA'
205 character(len=LENMEMPATH) :: simnam_mempath, hpc_mempath
206 character(len=LENMODELNAME) :: model_name
209 integer(I4B),
dimension(:),
contiguous,
pointer :: mranks_hpc
210 integer(I4B) :: i, model_idx
211 integer(I4B) :: target_rank
212 integer(I4B),
dimension(:),
allocatable :: rank_used
214 character(len=LINELENGTH) :: hpc_filename
217 this%model_ranks = -1
222 call mem_setptr(mnames,
'MNAME', simnam_mempath)
223 call mem_setptr(mnames_hpc,
'MNAME', hpc_mempath)
224 call mem_setptr(mranks_hpc,
'MRANK', hpc_mempath)
225 call mem_setptr(hpc_names,
'HPC6_FILENAME', simnam_mempath)
228 hpc_filename = hpc_names(1)
231 do i = 1,
size(mnames_hpc)
232 if (
ifind(mnames, mnames_hpc(i)) == -1)
then
233 model_name = mnames_hpc(i)
234 write (
errmsg, *)
"HPC input error: undefined model name (", &
235 trim(model_name),
")"
240 do i = 1,
size(mranks_hpc)
241 target_rank = mranks_hpc(i)
242 if (target_rank < 0 .or. target_rank >
nr_procs - 1)
then
243 model_name = mnames_hpc(i)
244 write (
errmsg,
'(a,i0,2a)')
"HPC input error: invalid target rank (", &
245 target_rank,
") for model ", trim(model_name)
254 do i = 1,
size(mnames_hpc)
255 model_idx =
ifind(mnames, mnames_hpc(i))
256 this%model_ranks(model_idx) = mranks_hpc(i)
260 do i = 1,
size(this%model_ranks)
261 if (this%model_ranks(i) == -1)
then
262 model_name = mnames(i)
263 write (
errmsg,
'(2a)')
"HPC input error: no target rank for model ", &
275 do i = 1,
size(this%model_ranks)
276 if (this%model_ranks(i) >= 0 .and. this%model_ranks(i) <
nr_procs)
then
277 rank_used(this%model_ranks(i) + 1) = 1
280 do i = 1,
size(rank_used)
281 if (rank_used(i) == 0)
then
282 write (
errmsg,
'(a,i0,a)')
"HPC input error: rank ", i - 1, &
283 " has no models assigned"
287 deallocate (rank_used)
300 integer(I4B) :: im, imm, ie, ip, cnt
301 integer(I4B) :: nr_models, nr_gwf_models
302 integer(I4B) :: nr_exchanges
303 integer(I4B) :: min_per_proc, nr_left
305 integer(I4B),
dimension(:),
allocatable :: nr_models_proc
306 character(len=LENPACKAGETYPE) :: model_type_str
307 character(len=LENMEMPATH) :: input_mempath
323 call mem_setptr(mtypes,
'MTYPE', input_mempath)
324 call mem_setptr(mnames,
'MNAME', input_mempath)
325 call mem_setptr(etypes,
'EXGTYPE', input_mempath)
326 call mem_setptr(emnames_a,
'EXGMNAMEA', input_mempath)
327 call mem_setptr(emnames_b,
'EXGMNAMEB', input_mempath)
330 nr_models =
size(mnames)
333 if (mtypes(im) ==
'GWF6')
then
334 nr_gwf_models = nr_gwf_models + 1
337 if (mtypes(im) ==
'GWF6' .or. &
338 mtypes(im) ==
'GWT6' .or. &
339 mtypes(im) ==
'GWE6')
then
343 model_type_str = mtypes(im)
344 write (
errmsg, *)
'Model type ', model_type_str, &
345 ' not supported in parallel mode.'
351 min_per_proc = nr_gwf_models /
nr_procs
352 nr_left = nr_gwf_models -
nr_procs * min_per_proc
356 nr_models_proc(ip) = min_per_proc
357 if (rank < nr_left)
then
358 nr_models_proc(ip) = nr_models_proc(ip) + 1
365 if (mtypes(im) ==
'GWF6')
then
366 if (nr_models_proc(rank + 1) == 0)
then
369 this%model_ranks(im) = rank
370 nr_models_proc(rank + 1) = nr_models_proc(rank + 1) - 1
375 nr_exchanges =
size(etypes)
377 if (mtypes(im) ==
'GWT6')
then
380 do ie = 1, nr_exchanges
381 if (etypes(ie) ==
'GWF6-GWT6' .and. mnames(im) == emnames_b(ie))
then
383 do imm = 1, nr_models
384 if (mnames(imm) == emnames_a(ie))
then
385 rank = this%model_ranks(imm)
389 this%model_ranks(im) = rank
394 else if (mtypes(im) ==
'GWE6')
then
395 do ie = 1, nr_exchanges
396 if (etypes(ie) ==
'GWF6-GWE6' .and. mnames(im) == emnames_b(ie))
then
398 do imm = 1, nr_models
399 if (mnames(imm) == emnames_a(ie))
then
400 rank = this%model_ranks(imm)
404 this%model_ranks(im) = rank
415 deallocate (nr_models_proc)
424 character(len=LENMEMPATH) :: input_mempath
438 integer(I4B) :: idx_a, idx_b
439 integer(I4B) :: rank_a, rank_b
440 integer(I4B) :: nr_exchanges
441 character(len=LINELENGTH) :: hpc_filename
442 character(len=LENMODELNAME) :: name_a, name_b
443 character(len=LINELENGTH) :: exg_type
447 call mem_setptr(mtypes,
'MTYPE', input_mempath)
448 call mem_setptr(mnames,
'MNAME', input_mempath)
449 call mem_setptr(etypes,
'EXGTYPE', input_mempath)
450 call mem_setptr(emnames_a,
'EXGMNAMEA', input_mempath)
451 call mem_setptr(emnames_b,
'EXGMNAMEB', input_mempath)
452 call mem_setptr(hpc_names,
'HPC6_FILENAME', input_mempath)
455 hpc_filename = hpc_names(1)
457 nr_exchanges =
size(etypes)
460 do ie = 1, nr_exchanges
461 if (etypes(ie) ==
'GWF6-GWT6' .or. etypes(ie) ==
'GWF6-GWE6')
then
462 idx_a =
ifind(mnames, emnames_a(ie))
463 idx_b =
ifind(mnames, emnames_b(ie))
464 rank_a = this%model_ranks(idx_a)
465 rank_b = this%model_ranks(idx_b)
466 if (rank_a /= rank_b)
then
467 name_a = emnames_a(ie)
468 name_b = emnames_b(ie)
469 exg_type = etypes(ie)
470 write (
errmsg,
'(7a)')
"HPC input error: models ", &
471 trim(name_a),
" and ", trim(name_b),
" with a ", &
472 trim(exg_type),
" coupling have to be assigned to the same rank"
492 type(
tabletype),
pointer :: inputtab => null()
493 character(len=LINELENGTH) :: tag, term
494 character(len=LENMEMPATH) :: input_mempath
499 integer(I4B) :: im, nr_models
503 call mem_setptr(mtypes,
'MTYPE', input_mempath)
504 call mem_setptr(mnames,
'MNAME', input_mempath)
507 nr_models =
size(mnames)
508 call table_cr(inputtab,
'HPC',
'HPC PARTITION DATA')
509 call inputtab%table_df(nr_models, 5,
iout)
513 call inputtab%initialize_column(tag, 8, alignment=
tableft)
515 call inputtab%initialize_column(tag, lenmodelname + 4, alignment=
tableft)
517 call inputtab%initialize_column(tag, 8, alignment=
tableft)
519 call inputtab%initialize_column(tag, 8, alignment=
tableft)
521 call inputtab%initialize_column(tag, 8, alignment=
tableft)
524 call inputtab%add_term(im)
526 call inputtab%add_term(term)
528 call inputtab%add_term(term)
529 call inputtab%add_term(this%model_ranks(im))
531 if (this%model_ranks(im) ==
proc_id) term =
'X'
532 call inputtab%add_term(term)
536 call inputtab%table_da()
537 deallocate (inputtab)
546 if (
associated(this%load_mask))
then
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
@ tabcenter
centered table column
@ tableft
left justified table column
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 print_load_balance(this)
Print the load balance table to the listing file.
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=linelength) simulation_mode
character(len=maxcharlen) warnmsg
warning message string
integer(i4b) iout
file unit number for simulation output
subroutine, public table_cr(this, name, title)
This class is used to store a single deferred-length character string. It was designed to work in an ...