Skip to content

Commit

Permalink
- option to print partition table to file
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr-deltares committed Dec 10, 2024
1 parent 2d8c5b6 commit 3959b52
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 12 deletions.
2 changes: 1 addition & 1 deletion autotest/test_par_hpc01.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_simulation(idx, ws):
highest_rank = rnk
partitions = [(n, highest_rank - r) for n, r in partitions]

hpc = flopy.mf6.ModflowUtlhpc(sim, partitions=partitions)
hpc = flopy.mf6.ModflowUtlhpc(sim, print_table=True, partitions=partitions)

tdis = flopy.mf6.ModflowTdis(sim, time_units="DAYS", nper=nper, perioddata=tdis_rc)

Expand Down
6 changes: 3 additions & 3 deletions doc/mf6io/mf6ivar/dfn/utl-hpc.dfn
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# flopy parent_name_type parent_package MFSimulation

block options
name print_input
name print_table
type keyword
reader urword
optional true
longname model print input to listing file
description keyword to indicate that the input will be printed.
longname model print table to listing file
description keyword to indicate that the partition table will be printed to the listing file.

block options
name dev_log_mpi
Expand Down
81 changes: 79 additions & 2 deletions src/Distributed/DistributedSim.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module DistributedSimModule
store_warning
use MemoryManagerModule, only: mem_allocate, mem_deallocate, mem_setptr, &
mem_print_detailed, get_isize
use MemoryManagerExtModule, only: mem_set_value
use MemoryHelperModule, only: create_mem_path

implicit none
Expand All @@ -21,6 +22,7 @@ module DistributedSimModule
integer(I4B), pointer :: nr_models !< the total (global) number of models, equals the length of the model block in mfsim.nam
integer(I4B), dimension(:), pointer, contiguous :: load_mask => null() !< mask for loading models and exchanges, 1 when active on this processor, else 0
integer(I4B), dimension(:), pointer, contiguous :: model_ranks => null() !< load balance: model rank (0,...,nr_procs-1) per global model id (array index)
logical(LGP), pointer :: print_ptable !< when true, the partition table is printed to file
contains
procedure :: create
procedure :: get_load_mask
Expand All @@ -31,6 +33,7 @@ module DistributedSimModule
procedure, private :: set_load_balance_from_input
procedure, private :: set_load_balance_default
procedure, private :: validate_load_balance
procedure, private :: print_load_balance
end type

! singleton, private member
Expand Down Expand Up @@ -67,6 +70,9 @@ subroutine create(this)
call mem_allocate(this%nr_models, 'NUMMODELS', this%memory_path)
this%nr_models = nmod

call mem_allocate(this%print_ptable, 'PRINT_PTABLE', this%memory_path)
this%print_ptable = .false.

end subroutine create

!> @brief Return pointer to the load mask for models
Expand Down Expand Up @@ -118,11 +124,13 @@ end subroutine create_load_mask
!> @brief Get the model load balance for the simulation
!<
function get_load_balance(this) result(mranks)
use UtlHpcInputModule, only: UtlHpcParamFoundType
class(DistributedSimType) :: this !< this distributed sim instance
integer(I4B), dimension(:), pointer :: mranks !< the load balance: array of ranks per model id
! local
integer(I4B) :: isize
character(len=LENMEMPATH) :: hpc_mempath
type(UtlHpcParamFoundType) :: found

! if load balance available, return here:
if (associated(this%model_ranks)) then
Expand All @@ -137,6 +145,10 @@ function get_load_balance(this) result(mranks)
hpc_mempath = create_mem_path('UTL', 'HPC', idm_context)
call get_isize('MNAME', hpc_mempath, isize)

! optional print input flag
call mem_set_value(this%print_ptable, 'PRINT_TABLE', hpc_mempath, &
found%print_table)

if (isize > 0) then
! HPC file present
if (nr_procs == 1) then
Expand All @@ -151,6 +163,10 @@ function get_load_balance(this) result(mranks)
call this%set_load_balance_from_input()
! check if valid configuration
call this%validate_load_balance()
! print to listing file
if (this%print_ptable) then
call this%print_load_balance()
end if
end if
else
! no HPC file present
Expand Down Expand Up @@ -390,6 +406,7 @@ end subroutine set_load_balance_default
!<
subroutine validate_load_balance(this)
class(DistributedSimType) :: this
! local
character(len=LENMEMPATH) :: input_mempath
type(CharacterStringType), dimension(:), contiguous, &
pointer :: mtypes !< model types
Expand Down Expand Up @@ -450,15 +467,75 @@ subroutine validate_load_balance(this)

end subroutine validate_load_balance

!> @brief Print the load balance table to the listing file
!<
subroutine print_load_balance(this)
use TableModule, only: TableType, table_cr
use ConstantsModule, only: TABLEFT, TABCENTER
use SimVariablesModule, only: iout, proc_id
class(DistributedSimType) :: this
! local
type(TableType), pointer :: inputtab => null()
character(len=LINELENGTH) :: tag, term
character(len=LENMEMPATH) :: input_mempath
type(CharacterStringType), dimension(:), contiguous, &
pointer :: mtypes !< model types
type(CharacterStringType), dimension(:), contiguous, &
pointer :: mnames !< model names
integer(I4B) :: im, nr_models

input_mempath = create_mem_path('SIM', 'NAM', idm_context)

call mem_setptr(mtypes, 'MTYPE', input_mempath)
call mem_setptr(mnames, 'MNAME', input_mempath)

! setup table
nr_models = size(mnames)
call table_cr(inputtab, 'HPC', 'HPC PARTITION DATA')
call inputtab%table_df(nr_models, 5, iout)

! add columns
tag = 'ID'
call inputtab%initialize_column(tag, 8, alignment=TABLEFT)
tag = 'NAME'
call inputtab%initialize_column(tag, LENMODELNAME + 4, alignment=TABLEFT)
tag = 'TYPE'
call inputtab%initialize_column(tag, 8, alignment=TABLEFT)
tag = 'RANK'
call inputtab%initialize_column(tag, 8, alignment=TABLEFT)
tag = 'LOCAL'
call inputtab%initialize_column(tag, 8, alignment=TABLEFT)

do im = 1, nr_models
call inputtab%add_term(im)
term = mnames(im)
call inputtab%add_term(term)
term = mtypes(im)
call inputtab%add_term(term)
call inputtab%add_term(this%model_ranks(im))
term = ''
if (this%model_ranks(im) == proc_id) term = 'X'
call inputtab%add_term(term)
end do

! deallocate
call inputtab%table_da()
deallocate (inputtab)

end subroutine print_load_balance

!> @brief clean up
!<
subroutine destroy(this)
class(DistributedSimType) :: this

call mem_deallocate(this%load_mask)
call mem_deallocate(this%model_ranks)
if (associated(this%load_mask)) then
call mem_deallocate(this%load_mask)
call mem_deallocate(this%model_ranks)
end if

call mem_deallocate(this%nr_models)
call mem_deallocate(this%print_ptable)

! delete singleton instance
if (associated(dist_sim)) deallocate (dist_sim)
Expand Down
12 changes: 6 additions & 6 deletions src/Idm/utl-hpcidm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module UtlHpcInputModule
public utl_hpc_subpackages

type UtlHpcParamFoundType
logical :: print_input = .false.
logical :: print_table = .false.
logical :: dev_log_mpi = .false.
logical :: mname = .false.
logical :: mrank = .false.
Expand All @@ -27,16 +27,16 @@ module UtlHpcInputModule
]

type(InputParamDefinitionType), parameter :: &
utlhpc_print_input = InputParamDefinitionType &
utlhpc_print_table = InputParamDefinitionType &
( &
'UTL', & ! component
'HPC', & ! subcomponent
'OPTIONS', & ! block
'PRINT_INPUT', & ! tag name
'PRINT_INPUT', & ! fortran variable
'PRINT_TABLE', & ! tag name
'PRINT_TABLE', & ! fortran variable
'KEYWORD', & ! type
'', & ! shape
'model print input to listing file', & ! longname
'model print table to listing file', & ! longname
.false., & ! required
.false., & ! multi-record
.false., & ! preserve case
Expand Down Expand Up @@ -101,7 +101,7 @@ module UtlHpcInputModule
type(InputParamDefinitionType), parameter :: &
utl_hpc_param_definitions(*) = &
[ &
utlhpc_print_input, &
utlhpc_print_table, &
utlhpc_dev_log_mpi, &
utlhpc_mname, &
utlhpc_mrank &
Expand Down

0 comments on commit 3959b52

Please sign in to comment.