Skip to content

Commit

Permalink
Add support for ESMF_RUNTIME_* variable override via configuration
Browse files Browse the repository at this point in the history
during ESMF_Initialize().
  • Loading branch information
theurich committed Aug 7, 2023
1 parent bda527f commit b57ee85
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 27 deletions.
109 changes: 91 additions & 18 deletions src/Superstructure/ESMFMod/src/ESMF_Init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ subroutine ESMF_Initialize(keywordEnforcer, configFilenameFromArgNum, &
! \item {\tt logKindFlag}
! \item {\tt globalResourceControl}
! \end{itemize}
!
! ESMF allows the user to affect certain details about the execution
! of an application through a number of run-time environment variables.
! The following list of variables are checked within the specified
! configuration file. If a matching label is found, the respective
! value is set, potentially overriding the value defined within the
! user environment for the same variable.
! \begin{itemize}
! \item {\tt ESMF\_RUNTIME\_PROFILE}
! \item {\tt ESMF\_RUNTIME\_PROFILE\_OUTPUT}
! \item {\tt ESMF\_RUNTIME\_PROFILE\_PETLIST}
! \item {\tt ESMF\_RUNTIME\_TRACE}
! \item {\tt ESMF\_RUNTIME\_TRACE\_CLOCK}
! \item {\tt ESMF\_RUNTIME\_TRACE\_PETLIST}
! \item {\tt ESMF\_RUNTIME\_TRACE\_COMPONENT}
! \item {\tt ESMF\_RUNTIME\_TRACE\_FLUSH}
! \item {\tt ESMF\_RUNTIME\_COMPLIANCECHECK}
! \end{itemize}
! \item [{[configKey]}]
! If present, use {\tt configKey} to find the map of predefined
! initialization options that are used during ESMF initialization.
Expand Down Expand Up @@ -606,7 +624,7 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
logical :: globalResourceControlSet, logAppendFlagSet
character(160) :: defaultLogFilenameSet, defaultLogFilenameS
character(:), allocatable :: stringAlloc
character(80) :: stringS, stringSU
character(80) :: stringS, stringSU, stringSet
type(ESMF_LogKind_Flag) :: logKindFlagSet
type(ESMF_CalKind_Flag) :: defaultCalKindSet

Expand Down Expand Up @@ -1076,22 +1094,6 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &
endif
endif

! optionally destroy the HConfigNode
if (validHConfigNode) then
call ESMF_HConfigDestroy(hconfigNode, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif

! optionally destroy the Config
if (.not.present(config)) then
call ESMF_ConfigDestroy(configInternal, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
else
config = configInternal ! return back to user
endif

endif ! have a default Config

if (present(configFilenameFromArgNum).or.present(configFilename)) &
Expand Down Expand Up @@ -1298,7 +1300,34 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &

! Ensure that at least the version number makes it into the log
call ESMF_LogFlush(rc=localrc)


if (haveConfig) then
! Ingest ESMF_RUNTIME_* settings from config -> possibly override environment
call ingest_environment_variable("ESMF_RUNTIME_PROFILE")
call ingest_environment_variable("ESMF_RUNTIME_PROFILE_OUTPUT")
call ingest_environment_variable("ESMF_RUNTIME_PROFILE_PETLIST")
call ingest_environment_variable("ESMF_RUNTIME_TRACE")
call ingest_environment_variable("ESMF_RUNTIME_TRACE_CLOCK")
call ingest_environment_variable("ESMF_RUNTIME_TRACE_PETLIST")
call ingest_environment_variable("ESMF_RUNTIME_TRACE_COMPONENT")
call ingest_environment_variable("ESMF_RUNTIME_TRACE_FLUSH")
call ingest_environment_variable("ESMF_RUNTIME_COMPLIANCECHECK")
! optionally destroy the HConfigNode
if (validHConfigNode) then
call ESMF_HConfigDestroy(hconfigNode, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
! optionally destroy the Config
if (.not.present(config)) then
call ESMF_ConfigDestroy(configInternal, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
else
config = configInternal ! return back to user
endif
endif

! if compliance checker is on, we want logs to have high precision timestamps
call c_esmc_getComplianceCheckJSON(complianceCheckIsOn, localrc)
if (localrc /= ESMF_SUCCESS) then
Expand Down Expand Up @@ -1362,6 +1391,50 @@ subroutine ESMF_FrameworkInternalInit(lang, configFilenameFromArgNum, &

if (rcpresent) rc = ESMF_SUCCESS

contains

subroutine ingest_environment_variable(env_var_name)
character(*), intent(in) :: env_var_name
if (validHConfigNode) then
isPresent = ESMF_HConfigIsDefined(hconfigNode, &
keyString=env_var_name, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if (isPresent) then
isPresent = .not.ESMF_HConfigIsNull(hconfigNode, &
keyString=env_var_name, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
else
call ESMF_ConfigFindLabel(configInternal, &
label="ESMF_RUNTIME_PROFILE:", isPresent=isPresent, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
if (isPresent) then
if (validHConfigNode) then
stringAlloc = ESMF_HConfigAsString(hconfigNode, &
keyString=env_var_name, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
stringSet = trim(stringAlloc)
else
call ESMF_ConfigGetAttribute(configInternal, stringS, &
label="defaultLogFilename:", default="---invalid---", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if (trim(stringS)/="---invalid---") then
stringSet = trim(stringS)
endif
endif
call ESMF_VMSetEnv(env_var_name, stringSet, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
end subroutine


end subroutine ESMF_FrameworkInternalInit
!------------------------------------------------------------------------------

Expand Down
27 changes: 18 additions & 9 deletions src/addon/ESMX/ESMX_App.F90
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,24 @@ program ESMX_App

! Validate hconfigNode against ESMX/App controlled key vocabulary
isFlag = ESMF_HConfigValidateMapKeys(hconfigNode, &
vocabulary=["defaultLogFilename ", & ! ESMF_Initialize option
"logAppendFlag ", & ! ESMF_Initialize option
"logKindFlag ", & ! ESMF_Initialize option
"defaultCalKind ", & ! ESMF_Initialize option
"globalResourceControl", & ! ESMF_Initialize option
"startTime ", & ! ESMX_App option
"stopTime ", & ! ESMX_App option
"logFlush ", & ! ESMX_App option
"fieldDictionary " & ! ESMX_App option
vocabulary=["defaultLogFilename ", & ! ESMF_Initialize option
"logAppendFlag ", & ! ESMF_Initialize option
"logKindFlag ", & ! ESMF_Initialize option
"defaultCalKind ", & ! ESMF_Initialize option
"globalResourceControl ", & ! ESMF_Initialize option
"ESMF_RUNTIME_PROFILE ", & ! ESMF_Initialize option
"ESMF_RUNTIME_PROFILE_OUTPUT ", & ! ESMF_Initialize option
"ESMF_RUNTIME_PROFILE_PETLIST", & ! ESMF_Initialize option
"ESMF_RUNTIME_TRACE ", & ! ESMF_Initialize option
"ESMF_RUNTIME_TRACE_CLOCK ", & ! ESMF_Initialize option
"ESMF_RUNTIME_TRACE_PETLIST ", & ! ESMF_Initialize option
"ESMF_RUNTIME_TRACE_COMPONENT", & ! ESMF_Initialize option
"ESMF_RUNTIME_TRACE_FLUSH ", & ! ESMF_Initialize option
"ESMF_RUNTIME_COMPLIANCECHECK", & ! ESMF_Initialize option
"startTime ", & ! ESMX_App option
"stopTime ", & ! ESMX_App option
"logFlush ", & ! ESMX_App option
"fieldDictionary " & ! ESMX_App option
], badKey=valueString, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=FILENAME)) &
Expand Down

0 comments on commit b57ee85

Please sign in to comment.