Skip to content

Commit

Permalink
grib header multio output manager
Browse files Browse the repository at this point in the history
  • Loading branch information
MircoValentiniECMWF committed Nov 27, 2024
1 parent eefdc79 commit 4ce840a
Show file tree
Hide file tree
Showing 6 changed files with 3,593 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/multiom/common/profile_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ MODULE PROFILE_MOD

#define PP_PROCEDURE_TYPE 'FUNCTION'
#define PP_PROCEDURE_NAME 'PROFILE_START_SIMULATION'
PP_THREAD_SAFE FUNCTION PROFILE_START_SIMULATION( PROFILE, DIRECTORY, PROC_ID, HOOKS ) RESULT(RET)
PP_THREAD_SAFE FUNCTION PROFILE_START_SIMULATION( PROFILE, DIRECTORY, &
& PROC_ID, THREAD_ID, HOOKS ) RESULT(RET)

! Symbols imported from other modules within the project.
USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K
Expand All @@ -67,6 +68,7 @@ PP_THREAD_SAFE FUNCTION PROFILE_START_SIMULATION( PROFILE, DIRECTORY, PROC_ID, H
TYPE(PROFILE_T), INTENT(INOUT) :: PROFILE
CHARACTER(LEN=*), INTENT(IN) :: DIRECTORY
INTEGER(KIND=JPIB_K), INTENT(IN) :: PROC_ID
INTEGER(KIND=JPIB_K), INTENT(IN) :: THREAD_ID
TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS

! Function result
Expand Down Expand Up @@ -117,7 +119,7 @@ PP_THREAD_SAFE FUNCTION PROFILE_START_SIMULATION( PROFILE, DIRECTORY, PROC_ID, H

! Write profile data
DUMMY = -99
PP_TRYCALL(ERRFLAG_UNABLE_TO_OPEN_PROFILE_FILE) PROFILE_WOPEN( DIRECTORY, PROC_ID, PROFILE%PROFUNIT_, NOW, TMP(4), HOOKS )
PP_TRYCALL(ERRFLAG_UNABLE_TO_OPEN_PROFILE_FILE) PROFILE_WOPEN( DIRECTORY, PROC_ID, THREAD_ID, PROFILE%PROFUNIT_, NOW, TMP(4), HOOKS )
PP_TRYCALL(ERRFLAG_UNABLE_TO_WRITE_PROFILE_DATA) PROFILE_WRITE_DATA( PROFILE%PROFUNIT_, 'START SIM.', TMP, TMP(1), DUMMY, DUMMY, HOOKS )

! Trace end of procedure (on success)
Expand Down Expand Up @@ -864,7 +866,7 @@ END FUNCTION PROFILE_END_SIMULATION

#define PP_PROCEDURE_TYPE 'FUNCTION'
#define PP_PROCEDURE_NAME 'PROFILE_WOPEN'
PP_THREAD_SAFE FUNCTION PROFILE_WOPEN( DIRECTORY, PROC_ID, PROFUNIT, NOW, TOTMEM, HOOKS ) RESULT(RET)
PP_THREAD_SAFE FUNCTION PROFILE_WOPEN( DIRECTORY, PROC_ID, THREAD_ID, PROFUNIT, NOW, TOTMEM, HOOKS ) RESULT(RET)

! Symbols imported from other modules within the project.
USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K
Expand All @@ -885,6 +887,7 @@ PP_THREAD_SAFE FUNCTION PROFILE_WOPEN( DIRECTORY, PROC_ID, PROFUNIT, NOW, TOTMEM
! Dummy arguments
CHARACTER(LEN=*), INTENT(IN) :: DIRECTORY
INTEGER(KIND=JPIB_K), INTENT(IN) :: PROC_ID
INTEGER(KIND=JPIB_K), INTENT(IN) :: THREAD_ID
INTEGER(KIND=JPIB_K), INTENT(OUT) :: PROFUNIT
INTEGER(KIND=JPIB_K), INTENT(IN) :: NOW
INTEGER(KIND=JPIB_K), INTENT(IN) :: TOTMEM
Expand Down Expand Up @@ -925,7 +928,7 @@ PP_THREAD_SAFE FUNCTION PROFILE_WOPEN( DIRECTORY, PROC_ID, PROFUNIT, NOW, TOTMEM
PP_TRYCALL(ERRFLAG_UNABLE_TO_GET_HOSTNAME) GET_HOSTNAME( HOSTNAME, HOOKS )

! Create the filename
WRITE( FILENAME, '(A,A,I6.6,A)', IOSTAT=STAT ) TRIM(DIRECTORY), '/profile_', PROC_ID, '.dat'
WRITE( FILENAME, '(A,A,I6.6,A,I6.6,A)', IOSTAT=STAT ) TRIM(DIRECTORY), '/profile_', PROC_ID, '_', THREAD_ID ,'.dat'
PP_DEBUG_CRITICAL_COND_THROW( STAT.NE.0, ERRFLAG_UNABLE_TO_WRITE_FILENAME )

! Open the file
Expand All @@ -937,6 +940,8 @@ PP_THREAD_SAFE FUNCTION PROFILE_WOPEN( DIRECTORY, PROC_ID, PROFUNIT, NOW, TOTMEM
PP_DEBUG_CRITICAL_COND_THROW( STAT.NE.0, ERRFLAG_UNABLE_TO_WRITE )
WRITE(PROFUNIT,'(A,I8)', IOSTAT=STAT ) '# PROC_IDX ::', PROC_ID
PP_DEBUG_CRITICAL_COND_THROW( STAT.NE.0, ERRFLAG_UNABLE_TO_WRITE )
WRITE(PROFUNIT,'(A,I8)', IOSTAT=STAT ) '# THREAD_IDX ::', THREAD_ID
PP_DEBUG_CRITICAL_COND_THROW( STAT.NE.0, ERRFLAG_UNABLE_TO_WRITE )
WRITE(PROFUNIT,'(A)', IOSTAT=STAT ) '# '
PP_DEBUG_CRITICAL_COND_THROW( STAT.NE.0, ERRFLAG_UNABLE_TO_WRITE )
WRITE(PROFUNIT,'(A)', IOSTAT=STAT ) '# This file has been automatically geneated by:'
Expand Down
140 changes: 140 additions & 0 deletions src/multiom/common/sysinfo_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ MODULE SYSINFO_MOD
! Whitelist of public symbols
PUBLIC :: GET_HOSTNAME
PUBLIC :: GET_PID
PUBLIC :: GET_TID
PUBLIC :: GET_NUM_THREADS
PUBLIC :: GET_MEM
PUBLIC :: TIC
PUBLIC :: TOC
Expand Down Expand Up @@ -240,6 +242,144 @@ END FUNCTION GET_PID
#undef PP_PROCEDURE_TYPE


#define PP_PROCEDURE_TYPE 'FUNCTION'
#define PP_PROCEDURE_NAME 'GET_TID'
PP_THREAD_SAFE FUNCTION GET_TID( TID, 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
#ifdef __OPENMP
USE :: OMP_LIB, ONLY: OMP_GET_THREAD_NUM
#endif

! 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) :: TID
TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS

! Function result
INTEGER(KIND=JPIB_K) :: RET

! Local variables
INTEGER :: THREAD_ID

! 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 )

#ifdef __OPENMP
THREAD_ID = OMP_GET_THREAD_NUM()
#else
THREAD_ID = 0 ! Default to thread ID 0 when OpenMP is not enabled
#endif

! Set dummy argument
TID = INT(THREAD_ID, KIND=JPIB_K)

! Trace end of procedure (on success)
PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS()

! Exit point (on success)
RETURN

END FUNCTION GET_TID
#undef PP_PROCEDURE_NAME
#undef PP_PROCEDURE_TYPE


#define PP_PROCEDURE_TYPE 'FUNCTION'
#define PP_PROCEDURE_NAME 'GET_NUM_THREADS'
PP_THREAD_SAFE FUNCTION GET_NUM_THREADS( NTH, HOOKS ) RESULT(RET)

! Symbols imported from other modules within the project
USE :: DATAKINDS_DEF_MOD, ONLY: JPIB_K
USE :: HOOKS_MOD, ONLY: HOOKS_T
#ifdef __OPENMP
USE :: OMP_LIB, ONLY: OMP_GET_THREAD_NUM
#endif

! 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) :: NTH
TYPE(HOOKS_T), INTENT(INOUT) :: HOOKS

! Function result
INTEGER(KIND=JPIB_K) :: RET

! Local variables
INTEGER :: NUM_THREADS

! 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 )

#ifdef __OPENMP
NUM_THREADS = OMP_GET_NUM_THREADS()
#else
NUM_THREADS = 1 ! Default to thread ID 0 when OpenMP is not enabled
#endif

! Set dummy argument
NTH = INT(NUM_THREADS, KIND=JPIB_K)

! Trace end of procedure (on success)
PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS()

! Exit point (on success)
RETURN

END FUNCTION GET_NUM_THREADS
#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)
Expand Down
1 change: 1 addition & 0 deletions src/multiom/output-manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set( MULTIOM_OUTPUT_MANAGER_MAIN_SOURCES
${MULTIOM_OUTPUT_MANAGER_DIR}/output_manager_factory_mod.F90
${MULTIOM_OUTPUT_MANAGER_DIR}/noop_mod.F90
${MULTIOM_OUTPUT_MANAGER_DIR}/dump_mod.F90
${MULTIOM_OUTPUT_MANAGER_DIR}/grib_header_to_multio_mod.F90
)

# Collect source files in module2
Expand Down
37 changes: 25 additions & 12 deletions src/multiom/output-manager/dump_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ MODULE DUMP_MOD

!> Process ID
INTEGER(KIND=JPIB_K) :: PID_=UNDEF_PARAM_E
INTEGER(KIND=JPIB_K) :: TID_=UNDEF_PARAM_E
INTEGER(KIND=JPIB_K) :: NUM_THREADS_=UNDEF_PARAM_E

!> Hostname
CHARACTER(LEN=256) :: HOSTNAME_=REPEAT(' ',256)
Expand All @@ -64,25 +66,25 @@ MODULE DUMP_MOD
TYPE(MODEL_PAR_T), POINTER :: MODEL_PAR_ => NULL()

!> Counter used to update the message file
INTEGER(KIND=JPIB_K) :: CNT_ = -99
INTEGER(KIND=JPIB_K) :: CNT_ = UNDEF_PARAM_E

!> Folder used to dump the files
CHARACTER(LEN=1024) :: OUT_DIR_ = REPEAT(' ',1024)

!> Unit used to write toc
INTEGER(KIND=JPIB_K) :: TOC_UNIT_ = -99_JPIB_K
INTEGER(KIND=JPIB_K) :: TOC_UNIT_ = UNDEF_PARAM_E

!> Unit used to write messages
INTEGER(KIND=JPIB_K) :: MSG_UNIT_ = -99_JPIB_K
INTEGER(KIND=JPIB_K) :: MSG_UNIT_ = UNDEF_PARAM_E

!> Unit used to write values
INTEGER(KIND=JPIB_K) :: VAL_UNIT_ = -99_JPIB_K
INTEGER(KIND=JPIB_K) :: VAL_UNIT_ = UNDEF_PARAM_E

!> Counter of the toc entries
INTEGER(KIND=JPIB_K) :: TOC_COUNTER_ = -99_JPIB_K
INTEGER(KIND=JPIB_K) :: TOC_COUNTER_ = UNDEF_PARAM_E

!> Write position in the toc
INTEGER(KIND=JPIB_K) :: TOC_WRITPOS_ = -99_JPIB_K
INTEGER(KIND=JPIB_K) :: TOC_WRITPOS_ = UNDEF_PARAM_E

!> Enable profiling
LOGICAL :: PROFILE_ = .FALSE.
Expand Down Expand Up @@ -782,7 +784,9 @@ PP_THREAD_SAFE FUNCTION DUMP_SETUP( THIS, YAMLFNAME, PROCESSOR_TOPO, MODEL_PARAM
USE :: IFS_PAR_MOD, ONLY: MODEL_PAR_T
USE :: IFS_PAR_MOD, ONLY: PAR_PRINT

USE :: SYSINFO_MOD, ONLY: GET_TID
USE :: SYSINFO_MOD, ONLY: GET_PID
USE :: SYSINFO_MOD, ONLY: GET_NUM_THREADS
USE :: SYSINFO_MOD, ONLY: GET_HOSTNAME
USE :: GENERAL_UTILS_MOD, ONLY: TOLOWER

Expand Down Expand Up @@ -868,7 +872,9 @@ PP_THREAD_SAFE FUNCTION DUMP_SETUP( THIS, YAMLFNAME, PROCESSOR_TOPO, MODEL_PARAM
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_WOPEN_VAL_FILE=22_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_CREATE_TOC_FILE_NAME=23_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_WOPEN_TOC_FILE=24_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_FLUSH_BEGIN_OF_SIMULATION=25_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_TOC_FLUSH_BEGIN_OF_SIMULATION=25_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_GET_TID=26_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_UNABLE_TO_GET_NUM_THREADS=27_JPIB_K


! Local variables declared by the preprocessor for debugging purposes
Expand All @@ -892,6 +898,8 @@ PP_THREAD_SAFE FUNCTION DUMP_SETUP( THIS, YAMLFNAME, PROCESSOR_TOPO, MODEL_PARAM

! Initialize debug variables
PP_TRYCALL(ERRFLAG_UNABLE_TO_GET_PID) GET_PID( THIS%PID_, HOOKS )
PP_TRYCALL(ERRFLAG_UNABLE_TO_GET_TID) GET_TID( THIS%TID_, HOOKS )
PP_TRYCALL(ERRFLAG_UNABLE_TO_GET_NUM_THREADS) GET_NUM_THREADS( THIS%NUM_THREADS_, HOOKS )
PP_TRYCALL(ERRFLAG_UNABLE_TO_GET_HOSTNAME) GET_HOSTNAME( THIS%HOSTNAME_, HOOKS )

! Check if the file exsts
Expand All @@ -913,7 +921,8 @@ PP_THREAD_SAFE FUNCTION DUMP_SETUP( THIS, YAMLFNAME, PROCESSOR_TOPO, MODEL_PARAM

! Profile
IF ( THIS%PROFILE_ ) THEN
PP_TRYCALL(ERRFLAG_PROFILE_START) PROFILE_START_SIMULATION( THIS%PROFILE_DATA_, '.', PROCESSOR_TOPO%MYPROC_IO, HOOKS )
PP_TRYCALL(ERRFLAG_PROFILE_START) PROFILE_START_SIMULATION( THIS%PROFILE_DATA_, TRIM(ADJUSTL(THIS%OUT_DIR_)), &
& PROCESSOR_TOPO%MYPROC_IO, THIS%TID_, HOOKS )
ENDIF

! Logging
Expand Down Expand Up @@ -957,11 +966,11 @@ PP_THREAD_SAFE FUNCTION DUMP_SETUP( THIS, YAMLFNAME, PROCESSOR_TOPO, MODEL_PARAM
ENDIF

! Create the toc file
PP_TRYCALL(ERRFLAG_CREATE_VAL_FILE_NAME) TOC_CREATE_NAME( THIS%OUT_DIR_, PROCESSOR_TOPO%MYPROC_IO, TOC_FNAME, HOOKS )
PP_TRYCALL(ERRFLAG_WOPEN_VAL_FILE) TOC_WOPEN( TRIM(TOC_FNAME), THIS%TOC_UNIT_, THIS%TOC_WRITPOS_, THIS%TOC_COUNTER_, HOOKS )
PP_TRYCALL(ERRFLAG_CREATE_TOC_FILE_NAME) TOC_CREATE_NAME( THIS%OUT_DIR_, PROCESSOR_TOPO%MYPROC_IO, TOC_FNAME, HOOKS )
PP_TRYCALL(ERRFLAG_WOPEN_TOC_FILE) TOC_WOPEN( TRIM(TOC_FNAME), THIS%TOC_UNIT_, THIS%TOC_WRITPOS_, THIS%TOC_COUNTER_, HOOKS )

! Add flush begin of simulation to toc
PP_TRYCALL(ERRFLAG_FLUSH_BEGIN_OF_SIMULATION) TOC_WRITE_FLUSH_BEGIN_OF_SIMULATION( THIS%TOC_UNIT_, THIS%TOC_WRITPOS_, THIS%TOC_COUNTER_, HOOKS )
PP_TRYCALL(ERRFLAG_TOC_FLUSH_BEGIN_OF_SIMULATION) TOC_WRITE_FLUSH_BEGIN_OF_SIMULATION( THIS%TOC_UNIT_, THIS%TOC_WRITPOS_, THIS%TOC_COUNTER_, HOOKS )

! Trace end of procedure (on success)
PP_TRACE_EXIT_PROCEDURE_ON_SUCCESS()
Expand Down Expand Up @@ -1033,8 +1042,12 @@ PP_THREAD_SAFE FUNCTION DUMP_SETUP( THIS, YAMLFNAME, PROCESSOR_TOPO, MODEL_PARAM
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unable to create the TOC file name' )
CASE (ERRFLAG_WOPEN_TOC_FILE)
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unable to open the TOC file' )
CASE (ERRFLAG_FLUSH_BEGIN_OF_SIMULATION)
CASE (ERRFLAG_TOC_FLUSH_BEGIN_OF_SIMULATION)
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unable to flush the begin of simulation to the TOC file' )
CASE (ERRFLAG_UNABLE_TO_GET_TID)
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unable to get the thread ID' )
CASE (ERRFLAG_UNABLE_TO_GET_NUM_THREADS)
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unable to get the number of threads' )
CASE DEFAULT
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Unhandled error' )
END SELECT
Expand Down
Loading

0 comments on commit 4ce840a

Please sign in to comment.