Skip to content

Commit

Permalink
my proposal tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
bena-nasa committed Jun 28, 2022
1 parent 6f62bff commit 420c3aa
Show file tree
Hide file tree
Showing 36 changed files with 816 additions and 19 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ add_subdirectory (base)
add_subdirectory (MAPL)
add_subdirectory (gridcomps)
add_subdirectory (griddedio)
add_subdirectory (tutorial)

if (PFUNIT_FOUND)
include (add_pfunit_ctest)
Expand Down
64 changes: 64 additions & 0 deletions generic/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ module MAPL_GenericMod
module procedure AddChildFromMeta
module procedure AddChildFromDSO_old
module procedure AddChildFromDSO
module procedure AddChildFromDSOMeta
end interface MAPL_AddChild

interface MAPL_AddImportSpec
Expand Down Expand Up @@ -4784,6 +4785,69 @@ recursive integer function AddChildFromGC(GC, name, SS, petList, configFile, RC)
_RETURN(ESMF_SUCCESS)
end function AddChildFromGC

recursive integer function AddChildFromDSOMeta(meta, name, userRoutine, grid, sharedObj, petList, configFile, parentGC, RC)

!ARGUMENTS:
type(MAPL_MetaComp), target, intent(INOUT) :: META
character(len=*), intent(IN) :: name
character(len=*), intent(in) :: userRoutine
type(ESMF_Grid), optional, intent(INout) :: grid
character(len=*), optional, intent(in) :: sharedObj

integer, optional , intent(IN ) :: petList(:)
character(len=*), optional, intent(IN ) :: configFile
type(ESMF_GridComp), optional, intent(IN ) :: parentGC
integer, optional , intent( OUT) :: rc
!EOP

integer :: status
integer :: userRC

integer :: I
type(MAPL_MetaComp), pointer :: child_meta
class(BaseProfiler), pointer :: t_p

class(Logger), pointer :: lgr
character(len=:), allocatable :: shared_object_library_to_load
character(len=:), allocatable :: extension

if (.not.allocated(meta%GCNameList)) then
! this is the first child to be added
allocate(meta%GCNameList(0), __STAT__)
end if

I = meta%get_num_children() + 1
AddChildFromDSOMeta = I

call AddChild_preamble(meta, I, name, grid=grid, configfile=configfile, parentGC=parentGC, petList=petlist, child_meta=child_meta,__RC__)

t_p => get_global_time_profiler()
call t_p%start(trim(name),__RC__)
call child_meta%t_profiler%start(__RC__)
call child_meta%t_profiler%start('SetService',__RC__)

extension = get_file_extension(SharedObj)
_ASSERT(is_supported_dso_name(SharedObj), "AddChildFromDSO: Unsupported shared library extension '"//extension//",.")

if (.not. is_valid_dso_name(SharedObj)) then
lgr => logging%get_logger('MAPL.GENERIC')
call lgr%warning("AddChildFromDSO: changing shared library extension from %a~ to system specific extension %a~", &
"'"//extension//"'", "'"//SYSTEM_DSO_EXTENSION//"'")
end if

shared_object_library_to_load = adjust_dso_name(sharedObj)
call ESMF_GridCompSetServices ( child_meta%gridcomp, userRoutine, &
sharedObj=shared_object_library_to_load,userRC=userRC,__RC__)
_VERIFY(userRC)

call child_meta%t_profiler%stop('SetService',__RC__)
call child_meta%t_profiler%stop(__RC__)
call t_p%stop(trim(name),__RC__)

_RETURN(ESMF_SUCCESS)
end function AddChildFromDSOMeta


!INTERFACE:
recursive integer function AddChildFromDSO(gc, name, userRoutine, grid, sharedObj, petList, configFile, RC)

Expand Down
2 changes: 1 addition & 1 deletion gridcomps/Cap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ esma_set_this (OVERRIDE MAPL.cap)
set (srcs
MAPL_Cap.F90
MAPL_CapGridComp.F90
MAPL_NUOPCWrapperMod.F90
#MAPL_NUOPCWrapperMod.F90
CapOptions.F90
ExternalGCStorage.F90
)
Expand Down
1 change: 1 addition & 0 deletions gridcomps/Cap/CapOptions.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module mapl_CapOptionsMod
logical :: use_comm_world = .true.
character(:), allocatable :: egress_file
character(:), allocatable :: cap_rc_file
character(:), allocatable :: root_dso
type (ESMF_LogKind_Flag) :: esmf_logging_mode = ESMF_LOGKIND_NONE
integer :: npes_model = -1
! only one of the next two options can have nonzero values
Expand Down
12 changes: 12 additions & 0 deletions gridcomps/Cap/FlapCLI.F90
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ subroutine add_command_line_options(options, unusable, rc)
integer :: status
_UNUSED_DUMMY(unusable)

call options%add(switch='--root_dso', &
help='name of root dso to use', &
required=.false., &
def='none', &
act='store', &
error=status)
_VERIFY(status)
call options%add(switch='--esmf_logtype', &
help='ESMF Logging type', &
required=.false., &
Expand Down Expand Up @@ -275,6 +282,9 @@ subroutine fill_cap_options(flapCLI, cap_options, unusable, rc)

integer, allocatable :: nodes_output_server(:)

call flapCLI%cli_options%get(val=buffer, switch='--root_dso', error=status); _VERIFY(status)
cap_options%root_dso = trim(buffer)

call flapCLI%cli_options%get(val=buffer, switch='--egress_file', error=status); _VERIFY(status)
cap_options%egress_file = trim(buffer)

Expand Down Expand Up @@ -357,6 +367,8 @@ function old_CapOptions_from_Flap( flapCLI, unusable, rc) result (cap_options)

integer, allocatable :: nodes_output_server(:)

call flapCLI%cli_options%get(val=buffer, switch='--root_dso', error=status); _VERIFY(status)
cap_options%root_dso = trim(buffer)
call flapCLI%cli_options%get(val=buffer, switch='--egress_file', error=status); _VERIFY(status)
cap_options%egress_file = trim(buffer)

Expand Down
21 changes: 16 additions & 5 deletions gridcomps/Cap/MAPL_Cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ module MAPL_CapMod
private
character(:), allocatable :: name
procedure(), nopass, pointer :: set_services => null()
logical :: non_dso = .false.
integer :: comm_world
integer :: rank
integer :: npes_member
character(:), allocatable :: root_dso

type (MAPL_CapOptions), allocatable :: cap_options
! misc
Expand Down Expand Up @@ -75,17 +77,20 @@ end function c_chdir

contains

function new_MAPL_Cap(name, set_services, unusable, cap_options, rc) result(cap)
function new_MAPL_Cap(name, unusable,set_services, cap_options, rc) result(cap)
type (MAPL_Cap) :: cap
character(*), intent(in) :: name
procedure() :: set_services
class (KeywordEnforcer), optional, intent(in) :: unusable
procedure(), optional :: set_services
type ( MAPL_CapOptions), optional, intent(in) :: cap_options
integer, optional, intent(out) :: rc
integer :: status

cap%name = name
cap%set_services => set_services
if (present(set_services)) then
cap%set_services => set_services
cap%non_dso = .true.
end if

if (present(cap_options)) then
allocate(cap%cap_options, source = cap_options)
Expand Down Expand Up @@ -314,8 +319,14 @@ subroutine initialize_cap_gc(this, unusable, n_run_phases, rc)

_UNUSED_DUMMY(unusable)

call MAPL_CapGridCompCreate(this%cap_gc, this%set_services, this%get_cap_rc_file(), &
this%name, this%get_egress_file(), n_run_phases=n_run_phases, rc=status)
if (this%non_dso) then
call MAPL_CapGridCompCreate(this%cap_gc, this%get_cap_rc_file(), &
this%name, this%get_egress_file(), n_run_phases=n_run_phases, root_set_services = this%set_services,rc=status)
else
_ASSERT(this%cap_options%root_dso /= 'none',"No set services specified, must pass a dso")
call MAPL_CapGridCompCreate(this%cap_gc, this%get_cap_rc_file(), &
this%name, this%get_egress_file(), n_run_phases=n_run_phases, root_dso = this%cap_options%root_dso,rc=status)
end if
_VERIFY(status)
_RETURN(_SUCCESS)
end subroutine initialize_cap_gc
Expand Down
39 changes: 26 additions & 13 deletions gridcomps/Cap/MAPL_CapGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module MAPL_CapGridCompMod
private
type (ESMF_GridComp) :: gc
procedure(), pointer, nopass :: root_set_services => null()
character(len=:), allocatable :: root_dso
character(len=:), allocatable :: final_file, name, cap_rc_file
integer :: nsteps, heartbeat_dt, perpetual_year, perpetual_month, perpetual_day
logical :: amiroot, started_loop_timer
Expand Down Expand Up @@ -107,13 +108,14 @@ module MAPL_CapGridCompMod
contains


subroutine MAPL_CapGridCompCreate(cap, root_set_services, cap_rc, name, final_file, unusable, n_run_phases, rc)
subroutine MAPL_CapGridCompCreate(cap, cap_rc, name, final_file, unusable, n_run_phases, root_set_services, root_dso, rc)
use mapl_StubComponent
type(MAPL_CapGridComp), intent(out), target :: cap
procedure() :: root_set_services
character(*), intent(in) :: cap_rc, name
character(len=*), optional, intent(in) :: final_file
class(KeywordEnforcer), optional, intent(in) :: unusable
procedure(), optional :: root_set_services
character(len=*), optional, intent(in) :: root_dso
integer, optional, intent(in) :: n_run_phases
integer, optional, intent(out) :: rc

Expand All @@ -126,7 +128,11 @@ subroutine MAPL_CapGridCompCreate(cap, root_set_services, cap_rc, name, final_fi
_UNUSED_DUMMY(unusable)

cap%cap_rc_file = cap_rc
cap%root_set_services => root_set_services
if (present(root_set_services)) cap%root_set_services => root_set_services
if (present(root_dso)) cap%root_dso = root_dso
if (present(root_dso) .and. present(root_set_services)) then
_FAIL("can only specify a setservice pointer or a dso to use")
end if
if (present(final_file)) then
allocate(cap%final_file, source=final_file)
end if
Expand Down Expand Up @@ -208,6 +214,7 @@ subroutine initialize_gc(gc, import_state, export_state, clock, rc)


type (MAPL_MetaComp), pointer :: maplobj, root_obj
character(len=ESMF_MAXSTR) :: sharedObj
type (ESMF_GridComp), pointer :: root_gc
procedure(), pointer :: root_set_services
type(MAPL_CapGridComp), pointer :: cap
Expand Down Expand Up @@ -510,13 +517,13 @@ subroutine initialize_gc(gc, import_state, export_state, clock, rc)

! Add a SINGLE_COLUMN flag in HISTORY.rc based on DYCORE value(from AGCM.rc)
!---------------------------------------------------------------------------
call ESMF_ConfigGetAttribute(cap%cf_root, value=DYCORE, Label="DYCORE:", rc=status)
_VERIFY(STATUS)
if (DYCORE == 'DATMO') then
snglcol = 1
call MAPL_ConfigSetAttribute(cap%cf_hist, value=snglcol, Label="SINGLE_COLUMN:", rc=status)
_VERIFY(STATUS)
end if
!call ESMF_ConfigGetAttribute(cap%cf_root, value=DYCORE, Label="DYCORE:", rc=status)
!_VERIFY(STATUS)
!if (DYCORE == 'DATMO') then
!snglcol = 1
!call MAPL_ConfigSetAttribute(cap%cf_hist, value=snglcol, Label="SINGLE_COLUMN:", rc=status)
!_VERIFY(STATUS)
!end if

! Detect if this a regular replay in the AGCM.rc
! ----------------------------------------------
Expand All @@ -535,8 +542,14 @@ subroutine initialize_gc(gc, import_state, export_state, clock, rc)
root_set_services => cap%root_set_services

call t_p%start('SetService')
cap%root_id = MAPL_AddChild(MAPLOBJ, name = root_name, SS = root_set_services, rc = status)
_VERIFY(status)
if (cap%root_dso == "none") then
cap%root_id = MAPL_AddChild(MAPLOBJ, name = root_name, SS = root_set_services, rc = status)
_VERIFY(status)
else
sharedObj = "libMAPL."//trim(cap%root_dso)//".so"
cap%root_id = MAPL_AddChild(MAPLOBJ, root_name, 'setservices_', sharedObj=sharedObj, rc=status)
_VERIFY(status)
end if
root_gc => maplobj%get_child_gridcomp(cap%root_id)
call MAPL_GetObjectFromGC(root_gc, root_obj, rc=status)
_ASSERT(cap%n_run_phases <= SIZE(root_obj%phase_run),"n_run_phases in cap_gc should not exceed n_run_phases in root")
Expand Down Expand Up @@ -1333,7 +1346,7 @@ subroutine print_throughput(rc)
LOOP_THROUGHPUT,INST_THROUGHPUT,RUN_THROUGHPUT,HRS_R,MIN_R,SEC_R,&
mem_committed_percent,mem_used_percent
1000 format(1x,'AGCM Date: ',i4.4,'/',i2.2,'/',i2.2,2x,'Time: ',i2.2,':',i2.2,':',i2.2, &
2x,'Throughput(days/day)[Avg Tot Run]: ',f8.1,1x,f8.1,1x,f8.1,2x,'TimeRemaining(Est) ',i3.3,':'i2.2,':',i2.2,2x, &
2x,'Throughput(days/day)[Avg Tot Run]: ',f12.1,1x,f12.1,1x,f12.1,2x,'TimeRemaining(Est) ',i3.3,':'i2.2,':',i2.2,2x, &
f5.1,'% : ',f5.1,'% Mem Comm:Used')

_RETURN(_SUCCESS)
Expand Down
5 changes: 5 additions & 0 deletions tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
install (PROGRAMS run_tutorial_case.sh DESTINATION bin)

add_subdirectory (driver_app)
add_subdirectory (grid_comps)
#add_subdirectory (tutorials)
8 changes: 8 additions & 0 deletions tutorial/driver_app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set (srcs
Example_Driver.F90
)

ecbuild_add_executable (TARGET Example_Driver.x SOURCES ${srcs})
target_link_libraries (Example_Driver.x PRIVATE MAPL OpenMP::OpenMP_Fortran FLAP::FLAP esmf)
target_compile_definitions (Example_Driver.x PRIVATE $<$<BOOL:${USE_EXTDATA2G}>:BUILD_WITH_EXTDATA2G>)

22 changes: 22 additions & 0 deletions tutorial/driver_app/Example_Driver.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define I_AM_MAIN

#include "MAPL_Generic.h"

program Example_Driver
use MPI
use MAPL
implicit none

type (MAPL_Cap) :: cap
type (MAPL_FlapCLI) :: cli
type (MAPL_CapOptions) :: cap_options
integer :: status

cli = MAPL_FlapCLI(description = 'GEOS AGCM', &
authors = 'GMAO')
cap_options = MAPL_CapOptions(cli)
cap = MAPL_Cap('example', cap_options = cap_options)
call cap%run(_RC)

end program Example_Driver

6 changes: 6 additions & 0 deletions tutorial/grid_comps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_subdirectory (hello_world_gridcomp)
add_subdirectory (no_children_gridcomp)
add_subdirectory (leaf_comp_a)
add_subdirectory (leaf_comp_b)
add_subdirectory (one_child_gridcomp)
add_subdirectory (two_siblings_gridcomp)
10 changes: 10 additions & 0 deletions tutorial/grid_comps/hello_world_gridcomp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
esma_set_this (OVERRIDE MAPL.hello_world_gridcomp)
set (srcs
HelloWorld_GridComp.F90
)

esma_add_library (${this} SRCS ${srcs} DEPENDENCIES MAPL.shared MAPL TYPE ${MAPL_LIBRARY_TYPE})
target_link_libraries (${this} PRIVATE esmf OpenMP::OpenMP_Fortran)
target_include_directories (${this} PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
set_target_properties (${this} PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
#target_compile_definitions(${this} PRIVATE SYSTEM_DSO_SUFFIX="${CMAKE_SHARED_LIBRARY_SUFFIX}")
Loading

0 comments on commit 420c3aa

Please sign in to comment.