Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapl3/tclune/improve mapl init #2820

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions generic3g/GriddedComponentDriver_smod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ module recursive subroutine finalize(this, unusable, phase_idx, rc)

end associate

call ESMF_GridCompDestroy(this%gridcomp, _RC)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine finalize
Expand Down Expand Up @@ -145,6 +147,7 @@ recursive module subroutine run_export_couplers(this, unusable, phase_idx, rc)
end associate

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine run_export_couplers

module subroutine clock_advance(this, rc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ subroutine register_imports(gridcomp, hconfig, rc)
iter_end = ESMF_HConfigIterEnd(var_list,_RC)
iter = iter_begin
do while (ESMF_HConfigIterLoop(iter,iter_begin,iter_end,rc=status))
_VERIFY(status)
call parse_item(iter, item_name, variable_names, _RC)
call add_specs(gridcomp, variable_names, _RC)
end do
Expand Down
47 changes: 39 additions & 8 deletions gridcomps/cap3g/Cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,49 @@ module mapl3g_Cap
contains


subroutine MAPL_run_driver(hconfig, unusable, rc)
subroutine MAPL_run_driver(hconfig, is_model_pet, unusable, rc)
USE MAPL_ApplicationSupport
type(ESMF_HConfig), intent(inout) :: hconfig
logical, intent(in) :: is_model_pet
class(KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

type(GriddedComponentDriver) :: driver
integer :: status

driver = make_driver(hconfig, _RC)
driver = make_driver(hconfig, is_model_pet, _RC)

call initialize_phases(driver, phases=GENERIC_INIT_PHASE_SEQUENCE, _RC)
call integrate(driver, _RC)
call driver%finalize(_RC)
if (is_model_pet) then
call initialize_phases(driver, phases=GENERIC_INIT_PHASE_SEQUENCE, _RC)
call integrate(driver, _RC)
call driver%finalize(_RC)
end if

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine MAPL_run_driver

function make_driver(hconfig, rc) result(driver)
function make_driver(hconfig, is_model_pet, rc) result(driver)
use mapl3g_GenericGridComp, only: generic_SetServices => setServices
type(GriddedComponentDriver) :: driver
type(ESMF_HConfig), intent(inout) :: hconfig
logical, intent(in) :: is_model_pet
integer, optional, intent(out) :: rc

type(ESMF_GridComp) :: cap_gridcomp
type(ESMF_Clock) :: clock
character(:), allocatable :: cap_name
integer :: status, user_status
type(ESMF_HConfig) :: cap_gc_hconfig
integer, allocatable :: petList(:)

cap_name = ESMF_HConfigAsString(hconfig, keystring='name', _RC)
! TODO: Rename to MAPL_CreateGridComp() ?
clock = create_clock(hconfig, _RC)

cap_gc_hconfig = ESMF_HConfigCreateAt(hconfig, keystring='cap_gc', _RC)
cap_gridcomp = create_grid_comp(cap_name, user_setservices(cap_setservices), cap_gc_hconfig, clock, _RC)
petList = get_model_pets(is_model_pet, _RC)
cap_gridcomp = create_grid_comp(cap_name, user_setservices(cap_setservices), cap_gc_hconfig, clock, petList=petList, _RC)

call ESMF_GridCompSetServices(cap_gridcomp, generic_setServices, userRC=user_status, _RC)
_VERIFY(user_status)

Expand All @@ -60,6 +68,29 @@ function make_driver(hconfig, rc) result(driver)
_RETURN(_SUCCESS)
end function make_driver

! Create function that accepts a logical flag returns list of mpi processes that have .true..
function get_model_pets(flag, rc) result(petList)
use mpi
integer, allocatable :: petList(:)
logical, intent(in) :: flag
integer, optional, intent(out) :: rc

integer :: status
type(ESMF_VM) :: vm
logical, allocatable, target :: flags(:)
integer :: world_comm
integer :: i, petCount

call ESMF_VMGetCurrent(vm, _RC)
call ESMF_VMGet(vm, petCount=petCount, mpiCommunicator=world_comm, _RC)
allocate(flags(petCount))
call MPI_Allgather(flag, 1, MPI_LOGICAL, flags, 1, MPI_LOGICAL, world_comm, status)
_VERIFY(status)
petList = pack([(i, i=0,petCount-1)], flags)

_RETURN(_SUCCESS)
end function get_model_pets

function create_clock(hconfig, rc) result(clock)
type(ESMF_Clock) :: clock
type(ESMF_HConfig), intent(in) :: hconfig
Expand Down
28 changes: 27 additions & 1 deletion gridcomps/cap3g/tests/basic_captest/cap.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
esmf:
logKindFlag: ESMF_LOGKIND_MULTI_ON_ERROR

#mapl:
mapl:
model_petcount: 1
# pflogger_cfg_file: pflogger.yaml
#
# servers:
# pfio:
# nodes: 1
# mit:
# nodes: 0

cap:
name: cap
Expand All @@ -13,6 +20,25 @@ cap:
stop: 2999-03-02T21:00:00
segment_duration: PT10H




















num_segments: 1 # segments per batch submission

servers:
Expand Down
3 changes: 2 additions & 1 deletion gridcomps/cap3g/tests/parent_child_captest/cap.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
esmf:
logKindFlag: ESMF_LOGKIND_MULTI_ON_ERROR

#mapl:
mapl:
model_petcount: 1
# pflogger_cfg_file: pflogger.yaml

cap:
Expand Down
2 changes: 1 addition & 1 deletion mapl3g/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ esma_set_this()


esma_add_library (${this}
SRCS mapl3g.F90 MaplFramework.F90
SRCS mapl3g.F90 MaplFramework.F90 ServerDriver.F90
DEPENDENCIES MAPL.generic3g MAPL.pfio MAPL.cap3g MAPL.gridcomps MAPL.griddedio MAPL.field_utils ${EXTDATA_TARGET}
ESMF::ESMF NetCDF::NetCDF_Fortran MPI::MPI_Fortran PFLOGGER::pflogger
TYPE ${MAPL_LIBRARY_TYPE}
Expand Down
11 changes: 7 additions & 4 deletions mapl3g/GEOS.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ program geos

integer :: status
type(ESMF_HConfig) :: hconfig
logical :: is_model_pet

call MAPL_Initialize(hconfig, _RC)
call run_geos(hconfig, _RC)
call MAPL_Initialize(hconfig, is_model_pet=is_model_pet, _RC)
call run_geos(hconfig, is_model_pet=is_model_pet, _RC)
call MAPL_Finalize(_RC)

contains

#undef I_AM_MAIN
#include "MAPL_Generic.h"

subroutine run_geos(hconfig, rc)
subroutine run_geos(hconfig, is_model_pet, rc)
type(ESMF_HConfig), intent(inout) :: hconfig
logical, intent(in) :: is_model_pet
integer, optional, intent(out) :: rc

logical :: has_cap_hconfig
Expand All @@ -29,7 +31,8 @@ subroutine run_geos(hconfig, rc)
has_cap_hconfig = ESMF_HConfigIsDefined(hconfig, keystring='cap', _RC)
_ASSERT(has_cap_hconfig, 'No cap section found in configuration file')
cap_hconfig = ESMF_HConfigCreateAt(hconfig, keystring='cap', _RC)
call MAPL_run_driver(cap_hconfig, _RC)

call MAPL_run_driver(cap_hconfig, is_model_pet=is_model_pet, _RC)
call ESMF_HConfigDestroy(cap_hconfig, _RC)

_RETURN(_SUCCESS)
Expand Down
Loading
Loading