From b21636506e22a0b24578728ccbeffd5342ae1aa2 Mon Sep 17 00:00:00 2001 From: Mirco Valentini Date: Sun, 24 Nov 2024 01:42:27 +0000 Subject: [PATCH] general improvements --- src/multiom/common/CMakeLists.txt | 3 +- src/multiom/common/general_utils_mod.F90 | 363 ++++++++++- .../common/{general_utils_c.c => sysinfo_c.c} | 0 src/multiom/common/sysinfo_mod.F90 | 573 ++++++++++++++++++ src/multiom/hooks/hooks_mod.F90 | 100 +-- src/multiom/hooks/log/CMakeLists.txt | 1 + src/multiom/hooks/log/log_mod.F90 | 454 ++++++++++++++ src/multiom/hooks/log/log_utils_mod.F90 | 83 +++ src/multiom/hooks/trace/trace_mod.F90 | 205 +++++++ src/multiom/output-manager/CMakeLists.txt | 2 +- .../output_manager_base_mod.F90 | 2 +- 11 files changed, 1685 insertions(+), 101 deletions(-) rename src/multiom/common/{general_utils_c.c => sysinfo_c.c} (100%) create mode 100644 src/multiom/common/sysinfo_mod.F90 diff --git a/src/multiom/common/CMakeLists.txt b/src/multiom/common/CMakeLists.txt index 0273ae274..84a9187b0 100644 --- a/src/multiom/common/CMakeLists.txt +++ b/src/multiom/common/CMakeLists.txt @@ -11,10 +11,11 @@ set( MULTIOM_COMMON_SOURCES ${MULTIOM_COMMON_DIR}/datakinds_def_mod.F90 ${MULTIOM_COMMON_DIR}/enumerators_mod.F90 ${MULTIOM_COMMON_DIR}/general_utils_mod.F90 - ${MULTIOM_COMMON_DIR}/general_utils_c.c ${MULTIOM_COMMON_DIR}/datetime_utils_mod.F90 ${MULTIOM_COMMON_DIR}/constants_mod.F90 ${MULTIOM_COMMON_DIR}/grib_codes_mod.F90 + ${MULTIOM_COMMON_DIR}/sysinfo_c.c + ${MULTIOM_COMMON_DIR}/sysinfo_mod.F90 CACHE INTERNAL "List of all sources in common directory" ) diff --git a/src/multiom/common/general_utils_mod.F90 b/src/multiom/common/general_utils_mod.F90 index 605c8dbbc..76dd433f6 100644 --- a/src/multiom/common/general_utils_mod.F90 +++ b/src/multiom/common/general_utils_mod.F90 @@ -16,7 +16,12 @@ MODULE GENERAL_UTILS_MOD PRIVATE ! Whitelist of public symbols +PUBLIC :: ENVVAR_IS_DEFINED +PUBLIC :: READ_ENVVAR PUBLIC :: REPLACE_ENVVAR_IN_STRING +PUBLIC :: READ_TYPE_FROM_ENV +PUBLIC :: READ_YAML_FROM_ENV +PUBLIC :: CUSTOM_FINDLOC PUBLIC :: TOLOWER PUBLIC :: TOUPPER @@ -153,14 +158,17 @@ PP_THREAD_SAFE FUNCTION REPLACE_ENVVAR_IN_STRING( INPSTR, OUTSTR, HOOKS ) RESULT ! Error handler PP_ERROR_HANDLER - ! Error handling variables - PP_DEBUG_PUSH_FRAME() + ! Initialization of bad path return value + PP_SET_ERR_FAILURE( RET ) #if defined( PP_DEBUG_ENABLE_ERROR_HANDLING ) !$omp critical(ERROR_HANDLER) BLOCK + ! Error handling variables + PP_DEBUG_PUSH_FRAME() + ! Handle different errors SELECT CASE(ERRIDX) @@ -371,7 +379,7 @@ PP_THREAD_SAFE FUNCTION READ_ENVVAR( CDENVVARNAME, CDENVVARVAL, NDLEN, HOOKS ) R BLOCK - ! Initialize error frame + ! Error handling variables PP_DEBUG_PUSH_FRAME() ! Handle different errors @@ -405,6 +413,354 @@ END FUNCTION READ_ENVVAR #undef PP_PROCEDURE_TYPE +!> +!> @brief Retrieves the output manager type from the 'OUTPUT_MANAGER_YAML' environment variable. +!> +!> This function reads the 'OUTPUT_MANAGER_YAML' environment variable to determine the configure +!> the main YAML configuration file. If the variable is not defined, the default value +!> '../output-manager-config.yaml' is assumed. +!> +!> @attention the folder is "../" because by default each instance of the output manager run in +!> the folder calles io_serv..d +!> +!> @param [out] OMYAML Name of the main YAML configuraiton file +!> +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'READ_YAML_FROM_ENV' +PP_THREAD_SAFE FUNCTION READ_YAML_FROM_ENV( OMYAML, HOOKS ) RESULT(RET) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + CHARACTER(LEN=*), INTENT(OUT) :: OMYAML + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + !> Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=JPIB_K) :: NENVLN + INTEGER(KIND=JPIB_K) :: STAT + LOGICAL :: IS_DEFINED + LOGICAL :: EX + + ! Error flags + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_ENVVAR_TOO_LONG = 1_JPIB_K + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_CHECK_ENVVAR = 2_JPIB_K + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_READ_ENVVAR = 3_JPIB_K + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_YAML_FILE_DOES_NOT_EXISTS = 4_JPIB_K + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Initialise the YAML name + OMYAML = REPEAT(' ',LEN(OMYAML)) + + ! Read Output Manager Type + PP_TRYCALL(ERRFLAG_UNABLE_TO_CHECK_ENVVAR) ENVVAR_IS_DEFINED( 'OUTPUT_MANAGER_YAML', IS_DEFINED, HOOKS, NDLEN=NENVLN ) + PP_DEBUG_DEVELOP_COND_THROW( (NENVLN.GT.LEN(OMYAML)), ERRFLAG_ENVVAR_TOO_LONG ) + + ! Read Output Manager Type + IF ( IS_DEFINED ) THEN + + ! Read the environment variable + PP_TRYCALL(ERRFLAG_UNABLE_TO_READ_ENVVAR) READ_ENVVAR( 'OUTPUT_MANAGER_YAML', OMYAML, NENVLN, HOOKS ) + + ! Check if the file exsts + INQUIRE( FILE=TRIM(OMYAML), EXIST=EX ) + PP_DEBUG_DEVELOP_COND_THROW( .NOT.EX, ERRFLAG_YAML_FILE_DOES_NOT_EXISTS ) + + ELSE + + ! Default value for output manager type when environment variable + ! is not defined. + ! "../" Because the output manager "main" directory is: "io_serv.0000?.d" + OMYAML = '../output-manager-config.yaml' + + ENDIF + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point + RETURN + +! Error handler +PP_ERROR_HANDLER + + ! Initialization of bad path return value + PP_SET_ERR_FAILURE( RET ) + +#if defined( PP_DEBUG_ENABLE_ERROR_HANDLING ) +!$omp critical(ERROR_HANDLER) + + BLOCK + + ! Error handling variables + PP_DEBUG_PUSH_FRAME() + + ! HAndle different errors + SELECT CASE(ERRIDX) + CASE (ERRFLAG_ENVVAR_TOO_LONG) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'OUTPUT_MANAGER_YAML env. var. too long' ) + CASE (ERRFLAG_UNABLE_TO_CHECK_ENVVAR) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Error checking: "OUTPUT_MANAGER_YAML" env. var.' ) + CASE (ERRFLAG_UNABLE_TO_READ_ENVVAR) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Error reading: "OUTPUT_MANAGER_YAML" env. var.' ) + CASE (ERRFLAG_YAML_FILE_DOES_NOT_EXISTS) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'YAML file does not exists' ) + CASE DEFAULT + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unhandled error' ) + END SELECT + + ! Trace end of procedure (on error) + PP_TRACE_EXIT_PROCEDURE_ON_ERROR() + + ! Write the error message and stop the program + PP_DEBUG_ABORT() + + END BLOCK + +!$omp end critical(ERROR_HANDLER) +#endif + + ! Exit point (on error) + RETURN + +END FUNCTION READ_YAML_FROM_ENV +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + +!> +!> @brief Retrieves the output manager type from the 'OUTPUT_MANAGER_TYPE' environment variable. +!> +!> This function reads the 'OUTPUT_MANAGER_TYPE' environment variable to determine the desired +!> type of output manager to be constructed. If the variable is not defined, the default value +!> 'NOOP' is assumed. +!> +!> @return The name of the output manager to be implemented. +!> +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'READ_TYPE_FROM_ENV' +PP_THREAD_SAFE FUNCTION READ_TYPE_FROM_ENV( OMTYPE, HOOKS ) RESULT(RET) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + CHARACTER(LEN=*), INTENT(OUT) :: OMTYPE + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + !> Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + CHARACTER(LEN=LEN(OMTYPE)) :: LOC_OMTYPE + INTEGER(KIND=JPIB_K) :: NENVLN + INTEGER(KIND=JPIB_K) :: STAT + LOGICAL :: IS_DEFINED + + ! Error flags + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_ENVVAR_TOO_LONG = 1_JPIB_K + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_CHECK_ENVVAR = 2_JPIB_K + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_READ_ENVVAR = 3_JPIB_K + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_CONVERT_UPPERCASE = 4_JPIB_K + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Initialise the YAML name + OMTYPE = REPEAT(' ',LEN(OMTYPE)) + LOC_OMTYPE = REPEAT(' ',LEN(OMTYPE)) + + ! Read Output Manager Type + PP_TRYCALL(ERRFLAG_UNABLE_TO_CHECK_ENVVAR) ENVVAR_IS_DEFINED( 'OUTPUT_MANAGER_TYPE', IS_DEFINED, HOOKS, NDLEN=NENVLN ) + PP_DEBUG_DEVELOP_COND_THROW( (NENVLN.GT.LEN(OMTYPE)), ERRFLAG_ENVVAR_TOO_LONG ) + + ! Read Output Manager Type + IF ( IS_DEFINED ) THEN + + ! Read the environment variable + PP_TRYCALL(ERRFLAG_UNABLE_TO_READ_ENVVAR) READ_ENVVAR( 'OUTPUT_MANAGER_TYPE', LOC_OMTYPE, NENVLN, HOOKS ) + + ! Convert to uppercase the environment variable + PP_TRYCALL(ERRFLAG_UNABLE_TO_CONVERT_UPPERCASE) TOUPPER( LOC_OMTYPE, OMTYPE, HOOKS ) + + ELSE + + ! Default value for output manager type when environment variable is not defined + OMTYPE = 'NOOP' + + ENDIF + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point + RETURN + +! Error handler +PP_ERROR_HANDLER + + ! Initialization of bad path return value + PP_SET_ERR_FAILURE( RET ) + +#if defined( PP_DEBUG_ENABLE_ERROR_HANDLING ) +!$omp critical(ERROR_HANDLER) + + BLOCK + + ! Error handling variables + PP_DEBUG_PUSH_FRAME() + + + ! HAndle different errors + SELECT CASE(ERRIDX) + CASE (ERRFLAG_ENVVAR_TOO_LONG) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'OUTPUT_MANAGER_TYPE env. var. too long' ) + CASE (ERRFLAG_UNABLE_TO_CHECK_ENVVAR) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Error checking: "OUTPUT_MANAGER_TYPE" env. var.' ) + CASE (ERRFLAG_UNABLE_TO_READ_ENVVAR) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Error reading: "OUTPUT_MANAGER_TYPE" env. var.' ) + CASE (ERRFLAG_UNABLE_TO_CONVERT_UPPERCASE) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Error converting to uppercase' ) + CASE DEFAULT + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unhandled error' ) + END SELECT + + ! Trace end of procedure (on error) + PP_TRACE_EXIT_PROCEDURE_ON_ERROR() + + ! Write the error message and stop the program + PP_DEBUG_ABORT() + + END BLOCK + +!$omp end critical(ERROR_HANDLER) +#endif + + ! Exit point (on error) + RETURN + +END FUNCTION READ_TYPE_FROM_ENV +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'CUSTOM_FINDLOC' +PP_THREAD_SAFE FUNCTION CUSTOM_FINDLOC( DAT, REF, LOC, HOOKS ) RESULT(RET) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + INTEGER(KIND=JPIB_K), DIMENSION(:), INTENT(IN) :: DAT + INTEGER(KIND=JPIB_K), INTENT(IN) :: REF + INTEGER(KIND=JPIB_K), INTENT(OUT) :: LOC + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + !> Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=JPIB_K) :: I + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + LOC = 0_JPIB_K + SearchLoop: DO I = 1, SIZE(DAT) + IF ( DAT(I) .EQ. REF ) THEN + LOC = I + EXIT SearchLoop + ENDIF + ENDDO SearchLoop + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point + RETURN + +END FUNCTION CUSTOM_FINDLOC +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + #define PP_PROCEDURE_TYPE 'FUNCTION' #define PP_PROCEDURE_NAME 'TOLOWER' PP_THREAD_SAFE FUNCTION TOLOWER( INPSTRING, OUTSTRING, HOOKS ) RESULT(RET) @@ -622,6 +978,7 @@ END FUNCTION TOUPPER #undef PP_PROCEDURE_NAME #undef PP_PROCEDURE_TYPE + END MODULE GENERAL_UTILS_MOD #undef PP_SECTION_NAME #undef PP_SECTION_TYPE diff --git a/src/multiom/common/general_utils_c.c b/src/multiom/common/sysinfo_c.c similarity index 100% rename from src/multiom/common/general_utils_c.c rename to src/multiom/common/sysinfo_c.c diff --git a/src/multiom/common/sysinfo_mod.F90 b/src/multiom/common/sysinfo_mod.F90 new file mode 100644 index 000000000..62e2d089d --- /dev/null +++ b/src/multiom/common/sysinfo_mod.F90 @@ -0,0 +1,573 @@ +! Include preprocessor utils +#include "output_manager_preprocessor_utils.h" +#include "output_manager_preprocessor_trace_utils.h" +#include "output_manager_preprocessor_logging_utils.h" +#include "output_manager_preprocessor_errhdl_utils.h" + + +#define PP_FILE_NAME 'sysinfo_mod.F90' +#define PP_SECTION_TYPE 'MODULE' +#define PP_SECTION_NAME 'SYSINFO_MOD' +MODULE SYSINFO_MOD + +IMPLICIT NONE + +!> Default visibility of the module +PRIVATE + +! Whitelist of public symbols +PUBLIC :: GET_HOSTNAME +PUBLIC :: GET_PID +PUBLIC :: GET_MEM +PUBLIC :: TIC +PUBLIC :: TOC +PUBLIC :: IS_LITTLE_ENDIAN + +CONTAINS + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'GET_HOSTNAME' +PP_THREAD_SAFE FUNCTION GET_HOSTNAME( CDHOSTNAME, HOOKS ) RESULT(RET) + + + ! Symbols imported from intrinsic modules + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_SIZE_T + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_NULL_CHAR + + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + CHARACTER(LEN=*), INTENT(OUT) :: CDHOSTNAME + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + !> Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=JPIB_K) :: I + INTEGER(KIND=C_SIZE_T) :: C_LENGTH + INTEGER(KIND=C_INT) :: C_STATUS + CHARACTER(KIND=C_CHAR,LEN=LEN(CDHOSTNAME)+1), TARGET :: C_CLHOSTNAME + + ! Local parameters + INTEGER(C_INT), PARAMETER :: HOST_NAME_MAX = 255 + + ! Error flags + INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_READ_HOSTNAME=1_JPIB_K + + ! Explicit interfaces + INTERFACE + FUNCTION C_GETHOSTNAME( C_CDVAR, C_NDLEN ) RESULT(C_STATUS) BIND(C, NAME="gethostname") + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_SIZE_T + IMPLICIT NONE + TYPE(C_PTR), VALUE, INTENT(IN) :: C_CDVAR + INTEGER(KIND=C_SIZE_T), VALUE, INTENT(IN) :: C_NDLEN + INTEGER(C_INT) :: C_STATUS + END FUNCTION C_GETHOSTNAME + END INTERFACE + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialise c buffers + C_CLHOSTNAME = REPEAT(C_NULL_CHAR,LEN(C_CLHOSTNAME)) + C_LENGTH = INT( LEN(C_CLHOSTNAME), C_INT ) + + ! Call the c function + C_STATUS = C_GETHOSTNAME( C_LOC(C_CLHOSTNAME), C_LENGTH ) + + ! Error handling + PP_DEBUG_CRITICAL_COND_THROW( C_STATUS.NE.0, ERRFLAG_UNABLE_TO_READ_HOSTNAME ) + + ! Copy the hostname back to a fortran string + CDHOSTNAME = REPEAT(' ', LEN(CDHOSTNAME)) + I = 1 + DO + IF ( I .LE. LEN(CDHOSTNAME) .AND. C_CLHOSTNAME(I:I) .NE. C_NULL_CHAR) THEN + CDHOSTNAME(I:I) = C_CLHOSTNAME(I:I) + I = I + 1 + ELSE + EXIT + ENDIF + ENDDO + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point + RETURN + +! Error handler +PP_ERROR_HANDLER + + ! Initialization of bad path return value + PP_SET_ERR_FAILURE( RET ) + +#if defined( PP_DEBUG_ENABLE_ERROR_HANDLING ) +!$omp critical(ERROR_HANDLER) + + BLOCK + + ! Error handling variables + PP_DEBUG_PUSH_FRAME() + + ! Handle different errors + SELECT CASE(ERRIDX) + CASE (ERRFLAG_UNABLE_TO_READ_HOSTNAME) + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unable to read hostname' ) + CASE DEFAULT + PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unhandled error' ) + END SELECT + + ! Trace end of procedure (on error) + PP_TRACE_EXIT_PROCEDURE_ON_ERROR() + + ! Write the error message and stop the program + PP_DEBUG_ABORT() + + END BLOCK + +!$omp end critical(ERROR_HANDLER) +#endif + + ! Exit point (on error) + RETURN + +END FUNCTION GET_HOSTNAME +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'GET_PID' +PP_THREAD_SAFE FUNCTION GET_PID( PID, HOOKS ) RESULT(RET) + + ! Symbols imported from intrinsic modules + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Function result + INTEGER(KIND=JPIB_K), INTENT(OUT) :: PID + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + ! Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=C_INT) :: C_PID + + ! Local parameters (Default permissions to be used to create a directory) + INTEGER(C_INT), PARAMETER :: S_IRWXU = 448 + + ! Explicit interfaces + INTERFACE + FUNCTION C_GETPID( ) RESULT(C_PID) BIND(C, NAME="getpid") + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT + IMPLICIT NONE + INTEGER(C_INT) :: C_PID + END FUNCTION C_GETPID + END INTERFACE + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Call the c function + C_PID = C_GETPID() + + ! Cast the result + PID = INT(C_PID, KIND(PID) ) + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point (on success) + RETURN + +END FUNCTION GET_PID +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'TOC' +PP_THREAD_SAFE FUNCTION TOC( NSEC, DNSEC, HOOKS ) RESULT(RET) + + ! Symbols imported from intrinsic modules + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT64_T + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Function result + INTEGER(KIND=JPIB_K), INTENT(IN) :: NSEC + INTEGER(KIND=JPIB_K), INTENT(OUT) :: DNSEC + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + ! Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=C_INT64_T), TARGET :: C_NSEC + INTEGER(KIND=C_INT64_T), TARGET :: C_DNSEC + + ! Explicit interfaces + INTERFACE + SUBROUTINE C_TOC( C_NSEC, C_DNSEC) BIND(C, NAME="om_toc") + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT64_T + IMPLICIT NONE + INTEGER(C_INT64_T), VALUE, INTENT(IN) :: C_NSEC + TYPE(C_PTR), VALUE, INTENT(IN) :: C_DNSEC + END SUBROUTINE C_TOC + END INTERFACE + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Initialisation of the variables + C_NSEC = INT( NSEC, C_INT64_T) + C_DNSEC = INT( -99, C_INT64_T) + + ! Call the utility to read the memory state + CALL C_TOC( C_NSEC, C_LOC(C_DNSEC) ) + + ! Cast the result + DNSEC = INT( C_DNSEC, JPIB_K) + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point (on success) + RETURN + +END FUNCTION TOC +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'TIC' +PP_THREAD_SAFE FUNCTION TIC( NSEC, HOOKS ) RESULT(RET) + + ! Symbols imported from intrinsic modules + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT64_T + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + INTEGER(KIND=JPIB_K), INTENT(OUT) :: NSEC + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + ! Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=C_INT64_T), TARGET :: C_NSEC + + ! Explicit interfaces + INTERFACE + SUBROUTINE C_TIC( C_NSEC ) BIND(C, NAME="om_tic") + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR + IMPLICIT NONE + TYPE(C_PTR), VALUE, INTENT(IN) :: C_NSEC + END SUBROUTINE C_TIC + END INTERFACE + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Initialisation of the variables + C_NSEC = INT( -99, C_INT64_T) + + ! Call the utility to read the memory state + CALL C_TIC( C_LOC(C_NSEC) ) + + ! Cast the result + NSEC = INT( C_NSEC, JPIB_K) + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point (on success) + RETURN + +END FUNCTION TIC +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'GET_MEM' +PP_THREAD_SAFE FUNCTION GET_MEM( TOT_MEM, SYS_USAGE, TASK_USAGE, HOOKS ) RESULT(RET) + + ! Symbols imported from intrinsic modules + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT64_T + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + INTEGER(KIND=JPIB_K), INTENT(OUT) :: TOT_MEM + INTEGER(KIND=JPIB_K), INTENT(OUT) :: SYS_USAGE + INTEGER(KIND=JPIB_K), INTENT(OUT) :: TASK_USAGE + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + ! Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=C_INT64_T), TARGET :: C_TOT_MEM + INTEGER(KIND=C_INT64_T), TARGET :: C_SYS_USAGE + INTEGER(KIND=C_INT64_T), TARGET :: C_TASK_USAGE + + ! Explicit interfaces + INTERFACE + SUBROUTINE C_GET_MEM_USAGE( C_TOT_MEM, C_SYS_USAGE, C_TASK_USAGE) BIND(C, NAME="om_get_mem_usage") + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR + IMPLICIT NONE + TYPE(C_PTR), VALUE, INTENT(IN) :: C_TOT_MEM + TYPE(C_PTR), VALUE, INTENT(IN) :: C_SYS_USAGE + TYPE(C_PTR), VALUE, INTENT(IN) :: C_TASK_USAGE + END SUBROUTINE C_GET_MEM_USAGE + END INTERFACE + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Initialisation of the variables + C_TOT_MEM = INT( -99, C_INT64_T) + C_SYS_USAGE = INT( -99, C_INT64_T) + C_TASK_USAGE = INT( -99, C_INT64_T) + + ! Call the utility to read the memory state + CALL C_GET_MEM_USAGE( C_LOC(C_TOT_MEM), C_LOC(C_SYS_USAGE), C_LOC(C_TASK_USAGE) ) + + ! Cast the result + TOT_MEM = INT( C_TOT_MEM, JPIB_K) + SYS_USAGE = INT( C_SYS_USAGE, JPIB_K) + TASK_USAGE = INT( C_TASK_USAGE, JPIB_K) + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point (on success) + RETURN + +END FUNCTION GET_MEM +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'IS_LITTLE_ENDIAN' +PP_THREAD_SAFE FUNCTION IS_LITTLE_ENDIAN( LDRET, HOOKS ) RESULT(RET) + + ! Symbols imported from intrinsic modules + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT8_T + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_LOC + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Function result + LOGICAL, INTENT(OUT) :: LDRET + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + ! Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + INTEGER(KIND=C_INT8_T), TARGET :: C_ISLITTLE + + ! Explicit interfaces + INTERFACE + SUBROUTINE C_IS_LITTLE_ENDIAN( C_ISLITTLE ) BIND(C, NAME="om_is_little_endian") + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR + IMPLICIT NONE + TYPE(C_PTR), VALUE, INTENT(IN) :: C_ISLITTLE + END SUBROUTINE C_IS_LITTLE_ENDIAN + END INTERFACE + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! Initialisation of the variables + C_ISLITTLE = INT( -99, C_INT8_T) + + ! Call the utility to read the memory state + CALL C_IS_LITTLE_ENDIAN( C_LOC(C_ISLITTLE) ) + + ! Cast the result + IF ( C_ISLITTLE .EQ. 0_C_INT8_T ) THEN + LDRET = .FALSE. + ELSE + LDRET = .TRUE. + ENDIF + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point (on success) + RETURN + +END FUNCTION IS_LITTLE_ENDIAN +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + +END MODULE SYSINFO_MOD +#undef PP_SECTION_NAME +#undef PP_SECTION_TYPE +#undef PP_FILE_NAME \ No newline at end of file diff --git a/src/multiom/hooks/hooks_mod.F90 b/src/multiom/hooks/hooks_mod.F90 index a723e4c83..a50d22b83 100644 --- a/src/multiom/hooks/hooks_mod.F90 +++ b/src/multiom/hooks/hooks_mod.F90 @@ -11,112 +11,22 @@ MODULE HOOKS_MOD USE :: DEBUG_MOD, ONLY: DEBUG_T + USE :: TRACE_MOD, ONLY: TRACER_T + USE :: LOG_MOD, ONLY: LOGGER_T IMPLICIT NONE !> Default visibility of the module members PRIVATE -#if 0 -MODEL_PAR_T -PARAMETRIZATION_T - -TYPE, ABSTRACT :: DEBUG_HOOK_A -CONTAINS - PROCEDURE, PUBLIC, PASS :: HAS_ERROR - PROCEDURE, PUBLIC, PASS :: OPEN_DEBUG_FRAME - PROCEDURE, PUBLIC, PASS :: CLOSE_DEBUG_FRAME - PROCEDURE, PUBLIC, PASS :: OPEN_LOCATION - PROCEDURE, PUBLIC, PASS :: CLOSE_LOCATION - PROCEDURE, PUBLIC, PASS :: OPEN_DUMMY - PROCEDURE, PUBLIC, PASS :: CLOSE_DUMMY - PROCEDURE, PUBLIC, PASS :: OPEN_ERROR_INFO - PROCEDURE, PUBLIC, PASS :: CLOSE_ERROR_INFO - PROCEDURE, PRIVATE, PASS :: WRITE_LOGICAL - PROCEDURE, PRIVATE, PASS :: WRITE_STRING - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_8 - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_16 - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_32 - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_64 - PROCEDURE, PRIVATE, PASS :: WRITE_REAL_32 - PROCEDURE, PRIVATE, PASS :: WRITE_REAL_64 - PROCEDURE, PRIVATE, PASS :: WRITE_LOGICAL_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_STRING_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_8_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_16_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_32_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_INTEGER_64_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_REAL_32_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_REAL_64_ARRAY - PROCEDURE, PRIVATE, PASS :: WRITE_MESSAGE_T - PROCEDURE, PRIVATE, PASS :: WRITE_PARAMETRIZATION_T - PROCEDURE, PRIVATE, PASS :: WRITE_CURRENT_TIME_T - PROCEDURE, PRIVATE, PASS :: WRITE_TIME_HISTORY_T - GENERIC, PUBLIC :: WRITE => WRITE_LOGICAL, WRITE_STRING, WRITE_INTEGER_8, WRITE_INTEGER_16, & -& WRITE_INTEGER_32, WRITE_INTEGER_64, & -& WRITE_REAL_32, WRITE_REAL_64,WRITE_LOGICAL_ARRAY, & -& WRITE_STRING_ARRAY, WRITE_INTEGER_8_ARRAY, & -& WRITE_INTEGER_16_ARRAY, WRITE_INTEGER_32_ARRAY, & -& WRITE_INTEGER_64_ARRAY, WRITE_REAL_32_ARRAY, & -& WRITE_REAL_64_ARRAY, WRITE_MESSAGE_T, & -& WRITE_PARAMETRIZATION_T, WRITE_CURRENT_TIME_T, & -& WRITE_TIME_HISTORY_T -END TYPE - -TYPE, ABSTRACT :: TRACE_HOOK_A -CONTAINS - PROCEDURE, PUBLIC, PASS :: TRACE_ENTER_PROCEDURE - PROCEDURE, PUBLIC, PASS :: PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS - PROCEDURE, PUBLIC, PASS :: TRACE_EXIT_PROCEDURE_ON_ERROR -END TYPE - -TYPE, ABSTRACT :: LOGGING_HOOK_A -CONTAINS - PROCEDURE, PUBLIC, PASS :: LOG_LOGICAL - PROCEDURE, PUBLIC, PASS :: LOG_STRING - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_8 - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_16 - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_32 - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_64 - PROCEDURE, PUBLIC, PASS :: LOG_REAL_32 - PROCEDURE, PUBLIC, PASS :: LOG_REAL_64 - PROCEDURE, PUBLIC, PASS :: LOG_LOGICAL_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_STRING_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_8_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_16_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_32_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_INTEGER_64_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_REAL_32_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_REAL_64_ARRAY - PROCEDURE, PUBLIC, PASS :: LOG_MESSAGE_T - PROCEDURE, PUBLIC, PASS :: LOG_PARAMETRIZATION_T - PROCEDURE, PUBLIC, PASS :: LOG_CURRENT_TIME_T - PROCEDURE, PUBLIC, PASS :: LOG_TIME_HISTORY_T - GENERIC, PUBLIC :: LOG => LOG_LOGICAL, LOG_STRING, LOG_INTEGER_8, LOG_INTEGER_16, & -& LOG_INTEGER_32, LOG_INTEGER_64, & -& LOG_REAL_32, LOG_REAL_64, LOG_LOGICAL_ARRAY, & -& LOG_STRING_ARRAY, LOG_INTEGER_8_ARRAY, & -& LOG_INTEGER_16_ARRAY, LOG_INTEGER_32_ARRAY, & -& LOG_INTEGER_64_ARRAY, LOG_REAL_32_ARRAY, & -& LOG_REAL_64_ARRAY, LOG_MESSAGE_T, & -& LOG_PARAMETRIZATION_T, LOG_CURRENT_TIME_T, & -& LOG_TIME_HISTORY_T -END TYPE - - -TYPE, ABSTRACT :: OPTIONS_HOOK_A -CONTAINS - PROCEDURE, PUBLIC, PASS :: GET -END TYPE -#endif - TYPE :: HOOKS_T LOGICAL :: VERBOSE_ ! CLASS(OPTIONS_HOOK_A), POINTER :: OPTIONS_HOOK_ => NULL() ! CLASS(LOGGING_HOOK_A), POINTER :: LOGGING_HOOK_ => NULL() - ! CLASS(TRACE_HOOK_A), POINTER :: TRACE_HOOK_ => NULL() - TYPE(DEBUG_T) :: DEBUG_HOOK_ + TYPE(TRACER_T) :: TRACE_HOOK_ + TYPE(LOGGER_T) :: LOG_HOOK_ + TYPE(DEBUG_T) :: DEBUG_HOOK_ END TYPE !> Public symbols diff --git a/src/multiom/hooks/log/CMakeLists.txt b/src/multiom/hooks/log/CMakeLists.txt index 6e4504b29..6d3e65ebb 100644 --- a/src/multiom/hooks/log/CMakeLists.txt +++ b/src/multiom/hooks/log/CMakeLists.txt @@ -8,6 +8,7 @@ set(OFFSET ${OFFSET}${DOFFSET}) # Collect source files in module2 set( MULTIOM_HOOKS_LOG_SOURCES + ${MULTIOM_HOOKS_LOG_DIR}/log_mod.F90 ${MULTIOM_HOOKS_LOG_DIR}/log_utils_mod.F90 CACHE INTERNAL "List of all sources in hooks/log directory" ) diff --git a/src/multiom/hooks/log/log_mod.F90 b/src/multiom/hooks/log/log_mod.F90 index e69de29bb..d7ecf9d3f 100644 --- a/src/multiom/hooks/log/log_mod.F90 +++ b/src/multiom/hooks/log/log_mod.F90 @@ -0,0 +1,454 @@ +! Include preprocessor utils +#include "output_manager_preprocessor_utils.h" +#include "output_manager_preprocessor_trace_utils.h" +#include "output_manager_preprocessor_logging_utils.h" +#include "output_manager_preprocessor_errhdl_utils.h" + + +#define PP_FILE_NAME 'log_mod.F90' +#define PP_SECTION_TYPE 'MODULE' +#define PP_SECTION_NAME 'LOG_MOD' +MODULE LOG_MOD + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + +! Default visibility +PRIVATE + +! Logging severity +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_TRACE = 0 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_DEBUG = 1 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_INFO = 2 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_NOTICE = 3 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_WARNING = 4 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_ERROR = 5 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_CRITICAL = 6 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_ALERT = 7 +INTEGER(KIND=JPIB_K), PARAMETER :: LOG_EMERGENCY = 8 + +! Datatype used by the logger to save the current hook handle +TYPE :: LOGGER_T +PRIVATE +CONTAINS +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_EMPTY => LOG_PROCEDURE_EMPTY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_BOOL => LOG_PROCEDURE_BOOL +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT8 => LOG_PROCEDURE_INT8 +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT16 => LOG_PROCEDURE_INT16 +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT32 => LOG_PROCEDURE_INT32 +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT64 => LOG_PROCEDURE_INT64 +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_REAL32 => LOG_PROCEDURE_REAL32 +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_REAL64 => LOG_PROCEDURE_REAL64 +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_BOOL_ARRAY => LOG_PROCEDURE_BOOL_ARRAY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT8_ARRAY => LOG_PROCEDURE_INT8_ARRAY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT16_ARRAY => LOG_PROCEDURE_INT16_ARRAY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT32_ARRAY => LOG_PROCEDURE_INT32_ARRAY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_INT64_ARRAY => LOG_PROCEDURE_INT64_ARRAY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_REAL32_ARRAY => LOG_PROCEDURE_REAL32_ARRAY +PROCEDURE, PRIVATE, NON_OVERRIDABLE, PASS :: LOG_REAL64_ARRAY => LOG_PROCEDURE_REAL64_ARRAY +GENERIC, PUBLIC :: LOG => LOG_EMPTY, LOG_BOOL, LOG_INT8, LOG_INT16, LOG_INT32, LOG_INT64, LOG_REAL32, LOG_REAL64, & + LOG_BOOL_ARRAY, LOG_INT8_ARRAY, LOG_INT16_ARRAY, LOG_INT32_ARRAY, LOG_INT64_ARRAY, & + LOG_REAL32_ARRAY, LOG_REAL64_ARRAY +END TYPE + +! Whitelist of public symbols (parameters) +PUBLIC :: LOG_TRACE +PUBLIC :: LOG_DEBUG +PUBLIC :: LOG_INFO +PUBLIC :: LOG_NOTICE +PUBLIC :: LOG_WARNING +PUBLIC :: LOG_ERROR +PUBLIC :: LOG_CRITICAL +PUBLIC :: LOG_ALERT +PUBLIC :: LOG_EMERGENCY + +! Whitelist of public symbols (types) +PUBLIC :: LOGGER_T + +CONTAINS + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_EMPTY( LOGGER, SEVERITY, MESSAGE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_EMPTY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_BOOL( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + LOGICAL, INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_BOOL + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT8( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT8 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT8), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT8 + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT16( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT16 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT16), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT16 + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT32( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT32 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT32), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT32 + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT64( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT64), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT64 + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_REAL32( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL32 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + REAL(KIND=REAL32), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_REAL32 + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_REAL64( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL64 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + REAL(KIND=REAL64), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_REAL64 + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_BOOL_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + LOGICAL, DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_BOOL_ARRAY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT8_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT8 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT8), DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT8_ARRAY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT16_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT16 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT16), DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT16_ARRAY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT32_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT32 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT32), DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT32_ARRAY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_INT64_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + INTEGER(KIND=INT64), DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_INT64_ARRAY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_REAL32_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL32 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + REAL(KIND=REAL32), DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_REAL32_ARRAY + + +PP_THREAD_SAFE SUBROUTINE LOG_PROCEDURE_REAL64_ARRAY( LOGGER, SEVERITY, MESSAGE, VALUE, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: REAL64 + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(LOGGER_T), INTENT(INOUT) :: LOGGER + INTEGER(KIND=JPIB_K), INTENT(IN) :: SEVERITY + CHARACTER(LEN=*), INTENT(IN) :: MESSAGE + REAL(KIND=REAL64), DIMENSION(:), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER, INTENT(IN) :: LINE + +END SUBROUTINE LOG_PROCEDURE_REAL64_ARRAY + +END MODULE LOG_MOD +#undef PP_SECTION_NAME +#undef PP_SECTION_TYPE +#undef PP_FILE_NAME diff --git a/src/multiom/hooks/log/log_utils_mod.F90 b/src/multiom/hooks/log/log_utils_mod.F90 index 6a9f5cd5b..8d7dce371 100644 --- a/src/multiom/hooks/log/log_utils_mod.F90 +++ b/src/multiom/hooks/log/log_utils_mod.F90 @@ -15,11 +15,13 @@ MODULE LOG_UTILS_MOD IMPLICIT NONE +! Default visibility PRIVATE !> Local parameters INTEGER(KIND=JPIB_K), PARAMETER :: MAX_STR_LEN = 32_JPIB_K + !> Local overloading of the intrinsic function TO_STRING INTERFACE TO_STRING MODULE PROCEDURE BOOL_TO_STRING @@ -49,10 +51,91 @@ MODULE LOG_UTILS_MOD !> Whitelist of public symbols PUBLIC :: MAX_STR_LEN PUBLIC :: TO_STRING +PUBLIC :: BYTES_TO_STRING CONTAINS + +#define PP_PROCEDURE_TYPE 'FUNCTION' +#define PP_PROCEDURE_NAME 'BYTES_TO_STRING' +PP_THREAD_SAFE FUNCTION BYTES_TO_STRING( BYTES, STR, HOOKS ) RESULT(RET) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + USE :: DATAKINDS_DEF_MOD, ONLY: JPRD_K + USE :: HOOKS_MOD, ONLY: HOOKS_T + + ! Symbols imported by the preprocessor for debugging purposes + PP_DEBUG_USE_VARS + + ! Symbols imported by the preprocessor for logging purposes + PP_LOG_USE_VARS + + ! Symbols imported by the preprocessor for tracing purposes + PP_TRACE_USE_VARS + +IMPLICIT NONE + + ! Dummy arguments + INTEGER(KIND=JPIB_K), INTENT(IN) :: BYTES + CHARACTER(LEN=MAX_STR_LEN), INTENT(OUT) :: STR + TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS + + ! Function result + INTEGER(KIND=JPIB_K) :: RET + + ! Local variables + REAL(KIND=JPRD_K) :: MEM + INTEGER(KIND=JPIB_K) :: SUFFIX + INTEGER(KIND=JPIB_K) :: I + CHARACTER(LEN=MAX_STR_LEN) :: TMP + + ! define the suffixes for memory units + CHARACTER(LEN=4), DIMENSION(7), PARAMETER :: UNITS(7) = ['[B] ', '[KB]', '[MB]', '[GB]', '[TB]', '[PB]', '[EB]'] + + ! Local variables declared by the preprocessor for debugging purposes + PP_DEBUG_DECL_VARS + + ! Local variables declared by the preprocessor for logging purposes + PP_LOG_DECL_VARS + + ! Local variables declared by the preprocessor for tracing purposes + PP_TRACE_DECL_VARS + + ! Trace begin of procedure + PP_TRACE_ENTER_PROCEDURE() + + ! Initialization of good path return value + PP_SET_ERR_SUCCESS( RET ) + + ! convert bytes to the appropriate unit + MEM = REAL(BYTES, JPRD_K) + DO I = 1, SIZE(UNITS) + IF ( MEM .LT. 1024.0_JPRD_K ) THEN + SUFFIX = I + EXIT + ENDIF + MEM = MEM / 1024.0_JPRD_K + END DO + + ! format the memory value with the appropriate suffix + TMP = REPEAT(' ', MAX_STR_LEN) + STR = REPEAT(' ', MAX_STR_LEN) + WRITE(TMP, '(F10.2)') MEM + STR = TRIM(ADJUSTL(TMP))//' '//TRIM(ADJUSTL(UNITS(I))) + + ! Trace end of procedure (on success) + PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS() + + ! Exit point (on success) + RETURN + +END FUNCTION BYTES_TO_STRING +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + #define PP_PROCEDURE_TYPE 'FUNCTION' #define PP_PROCEDURE_NAME 'BOOL_TO_STRING' PP_THREAD_SAFE FUNCTION BOOL_TO_STRING( VAL, STR, HOOKS ) RESULT(RET) diff --git a/src/multiom/hooks/trace/trace_mod.F90 b/src/multiom/hooks/trace/trace_mod.F90 index e69de29bb..36e24abbf 100644 --- a/src/multiom/hooks/trace/trace_mod.F90 +++ b/src/multiom/hooks/trace/trace_mod.F90 @@ -0,0 +1,205 @@ +! Include preprocessor utils +#include "output_manager_preprocessor_utils.h" +#include "output_manager_preprocessor_trace_utils.h" +#include "output_manager_preprocessor_logging_utils.h" +#include "output_manager_preprocessor_errhdl_utils.h" + + +#define PP_FILE_NAME 'trace_mod.F90' +#define PP_SECTION_TYPE 'MODULE' +#define PP_SECTION_NAME 'TRACE_MOD' +MODULE TRACE_MOD + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPTR_K + +IMPLICIT NONE + +! Default visibility +PRIVATE + +! Datatype used by the traces to save the current hook handle +TYPE :: TRACE_HOOK_T + REAL(KIND=JPTR_K) :: ZHOOK_HANDLE_ +END TYPE + +! The tracer type +TYPE :: TRACER_T + PRIVATE +CONTAINS + PROCEDURE, PUBLIC, NON_OVERRIDABLE, PASS :: ENTER_PROCEDURE => TRACE_ENTER_PROCEDURE + PROCEDURE, PUBLIC, NON_OVERRIDABLE, PASS :: EXIT_PROCEDURE_ON_SUCCESS => TRACE_EXIT_PROCEDURE_ON_SUCCESS + PROCEDURE, PUBLIC, NON_OVERRIDABLE, PASS :: EXIT_PROCEDURE_ON_ERROR => TRACE_EXIT_PROCEDURE_ON_ERROR +END TYPE + +! Explicit interface (same interface used by doctor hook) +INTERFACE + SUBROUTINE DR_HOOK_DEFAULT8_IF(CDNAME,KSWITCH,PKEY) + USE :: DATAKINDS_DEF_MOD, ONLY: JPIM_K + USE :: DATAKINDS_DEF_MOD, ONLY: JPTR_K + IMPLICIT NONE + CHARACTER(LEN=*), INTENT(IN) :: CDNAME + INTEGER(KIND=JPIM_K), INTENT(IN) :: KSWITCH + REAL(KIND=JPTR_K), INTENT(INOUT) :: PKEY + END SUBROUTINE DR_HOOK_DEFAULT8_IF +END INTERFACE + +! Pointer to the tracer handler +PROCEDURE(DR_HOOK_DEFAULT8_IF), POINTER :: DR_HOOK => NULL() +LOGICAL :: LHOOK_ = .FALSE. + + +! Whitelist of public symbols (types) +PUBLIC :: TRACER_T +PUBLIC :: TRACE_HOOK_T + +! Whitelist of public symbols (procedures) +PUBLIC :: OM_SET_DR_HOOK + +CONTAINS + + + +#define PP_PROCEDURE_TYPE 'SUBROUTINE' +#define PP_PROCEDURE_NAME 'OM_SET_DR_HOOK' +PP_THREAD_SAFE SUBROUTINE OM_SET_DR_HOOK( LHOOK, DR_HOOK_PROCEDURE ) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + LOGICAL, INTENT(IN) :: LHOOK + PROCEDURE(DR_HOOK_DEFAULT8_IF) :: DR_HOOK_PROCEDURE + +! Initialize the local static variables +!$omp single + LHOOK_ = LHOOK + DR_HOOK => DR_HOOK_PROCEDURE +!$omp end single + + ! Return the function result + RETURN + +END SUBROUTINE OM_SET_DR_HOOK +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + + + +#define PP_PROCEDURE_TYPE 'SUBROUTINE' +#define PP_PROCEDURE_NAME 'TRACE_ENTER_PROCEDURE' +PP_THREAD_SAFE SUBROUTINE TRACE_ENTER_PROCEDURE( THIS, TRACER, FNAME, SECTION_TYPE, & +& SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIM_K + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(TRACER_T), INTENT(INOUT) :: THIS + TYPE(TRACE_HOOK_T), INTENT(INOUT) :: TRACER + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER(KIND=JPIM_K), INTENT(IN) :: LINE + + !> Function result + INTEGER(KIND=JPIB_K) :: RET + + IF ( ASSOCIATED(DR_HOOK) .AND. LHOOK_ ) THEN + CALL DR_HOOK( TRIM(SECTION_NAME)//'::'//TRIM(PROC_NAME), 0, TRACER%ZHOOK_HANDLE_ ) + ENDIF + + RETURN + +END SUBROUTINE TRACE_ENTER_PROCEDURE +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + + +#define PP_PROCEDURE_TYPE 'SUBROUTINE' +#define PP_PROCEDURE_NAME 'TRACE_EXIT_PROCEDURE_ON_SUCCESS' +PP_THREAD_SAFE SUBROUTINE TRACE_EXIT_PROCEDURE_ON_SUCCESS( THIS, TRACER, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIM_K + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(TRACER_T), INTENT(INOUT) :: THIS + TYPE(TRACE_HOOK_T), INTENT(INOUT) :: TRACER + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER(KIND=JPIM_K), INTENT(IN) :: LINE + + !> Function result + INTEGER(KIND=JPIB_K) :: RET + + IF ( ASSOCIATED(DR_HOOK) .AND. LHOOK_ ) THEN + CALL DR_HOOK( TRIM(SECTION_NAME)//'::'//TRIM(PROC_NAME), 1, TRACER%ZHOOK_HANDLE_ ) + ENDIF + + RETURN + +END SUBROUTINE TRACE_EXIT_PROCEDURE_ON_SUCCESS +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + + +#define PP_PROCEDURE_TYPE 'SUBROUTINE' +#define PP_PROCEDURE_NAME 'TRACE_EXIT_PROCEDURE_ON_ERROR' +PP_THREAD_SAFE SUBROUTINE TRACE_EXIT_PROCEDURE_ON_ERROR( THIS, TRACER, FNAME, & +& SECTION_TYPE, SECTION_NAME, PROC_TYPE, PROC_NAME, LINE ) + + ! Symbolds imported from intrinsic modules + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: ERROR_UNIT + + ! Symbols imported from other modules within the project. + USE :: DATAKINDS_DEF_MOD, ONLY: JPIM_K + USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K + +IMPLICIT NONE + + ! Dummy arguments + CLASS(TRACER_T), INTENT(INOUT) :: THIS + TYPE(TRACE_HOOK_T), INTENT(INOUT) :: TRACER + CHARACTER(LEN=*), INTENT(IN) :: FNAME + CHARACTER(LEN=*), INTENT(IN) :: SECTION_TYPE + CHARACTER(LEN=*), INTENT(IN) :: SECTION_NAME + CHARACTER(LEN=*), INTENT(IN) :: PROC_TYPE + CHARACTER(LEN=*), INTENT(IN) :: PROC_NAME + INTEGER(KIND=JPIM_K), INTENT(IN) :: LINE + + !> Function result + INTEGER(KIND=JPIB_K) :: RET +!$omp critical(ERROR_HANDLER) + WRITE(ERROR_UNIT,*) 'ERROR: ', TRIM(SECTION_NAME)//'::'//TRIM(PROC_NAME), ' failed at line ', LINE +!$omp end critical(ERROR_HANDLER) + + RETURN + +END SUBROUTINE TRACE_EXIT_PROCEDURE_ON_ERROR +#undef PP_PROCEDURE_NAME +#undef PP_PROCEDURE_TYPE + + + +END MODULE TRACE_MOD +#undef PP_SECTION_NAME +#undef PP_SECTION_TYPE +#undef PP_FILE_NAME diff --git a/src/multiom/output-manager/CMakeLists.txt b/src/multiom/output-manager/CMakeLists.txt index 56f60089d..58c6f5023 100644 --- a/src/multiom/output-manager/CMakeLists.txt +++ b/src/multiom/output-manager/CMakeLists.txt @@ -10,7 +10,7 @@ set(OFFSET ${OFFSET}${DOFFSET}) set( MULTIOM_OUTPUT_MANAGER_MAIN_SOURCES ${MULTIOM_OUTPUT_MANAGER_DIR}/output_manager_base_mod.F90 ${MULTIOM_OUTPUT_MANAGER_DIR}/output_manager_factory_mod.F90 - ${MULTIOM_OUTPUT_MANAGER_DIR}/noop_output_manager_mod.F90 + # ${MULTIOM_OUTPUT_MANAGER_DIR}/noop_output_manager_mod.F90 ) # Collect source files in module2 diff --git a/src/multiom/output-manager/output_manager_base_mod.F90 b/src/multiom/output-manager/output_manager_base_mod.F90 index e0a55e3c6..4a0a4d098 100644 --- a/src/multiom/output-manager/output_manager_base_mod.F90 +++ b/src/multiom/output-manager/output_manager_base_mod.F90 @@ -80,7 +80,7 @@ MODULE OUTUPUT_MANAGER_BASE_MOD !> !> @return The return code of the function !> -PP_THREAD_SAFE FUNCTION READ_CFG_FROM_YAML_IF( THIS, CFG, HOOKS ) RESULT(RET) +PP_THREAD_SAFE FUNCTION READ_CFG_FROM_YAML_IF( THIS, CFG, HOOKS ) RESULT(RET) USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K USE :: FCKIT_CONFIGURATION_MODULE, ONLY: FCKIT_CONFIGURATION USE :: HOOKS_MOD, ONLY: HOOKS_T