Skip to content

Commit

Permalink
Merge branch 'release/MAPL-v3' into feature/bmauer/mapl3g_bundle_writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mathomp4 authored May 14, 2024
2 parents 50f5b64 + f19c835 commit d3fc454
Show file tree
Hide file tree
Showing 9 changed files with 473 additions and 103 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add GNU UFS-like CI test

### Changed

### Fixed
Expand Down
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
1 change: 1 addition & 0 deletions gridcomps/History3G/HistoryCollectionGridComp_private.F90
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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
48 changes: 40 additions & 8 deletions gridcomps/cap3g/Cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,50 @@ module mapl3g_Cap
contains


subroutine MAPL_run_driver(hconfig, unusable, rc)
subroutine MAPL_run_driver(hconfig, is_model_pet, unusable, servers, rc)
USE MAPL_ApplicationSupport
type(ESMF_HConfig), intent(inout) :: hconfig
logical, intent(in) :: is_model_pet
class(KeywordEnforcer), optional, intent(in) :: unusable
type(ESMF_GridComp), optional, intent(in) :: servers(:)
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 +69,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
9 changes: 8 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 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
6 changes: 5 additions & 1 deletion mapl3g/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
esma_set_this()

set (srcs
mapl3g.F90
MaplFramework.F90
)

esma_add_library (${this}
SRCS mapl3g.F90 MaplFramework.F90
SRCS ${srcs}
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 SHARED
Expand Down
13 changes: 9 additions & 4 deletions mapl3g/GEOS.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ program geos

integer :: status
type(ESMF_HConfig) :: hconfig
logical :: is_model_pet
type(ESMF_GridComp), allocatable :: servers(:)

call MAPL_Initialize(hconfig, _RC)
call run_geos(hconfig, _RC)
call MAPL_Initialize(hconfig, is_model_pet=is_model_pet, servers=servers, _RC)
call run_geos(hconfig, is_model_pet=is_model_pet, servers=servers, _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, servers, rc)
type(ESMF_HConfig), intent(inout) :: hconfig
logical, intent(in) :: is_model_pet
type(ESMF_GridComp), optional, intent(in) :: servers(:)
integer, optional, intent(out) :: rc

logical :: has_cap_hconfig
Expand All @@ -29,7 +33,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, servers=servers, _RC)
call ESMF_HConfigDestroy(cap_hconfig, _RC)

_RETURN(_SUCCESS)
Expand Down
Loading

0 comments on commit d3fc454

Please sign in to comment.