📄 mpe_log.c
字号:
/* (C) 2001 by Argonne National Laboratory. See COPYRIGHT in top-level directory.*/#include "mpe_logging_conf.h"#if defined( HAVE_SYS_TYPES_H)#include <sys/types.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )/* Needed for getenv */#include <stdlib.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STRING_H )#include <string.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDIO_H )#include <stdio.h>#endif#include "mpe_log.h"#include "mpe_log_thread.h"#if !defined( CLOG_NOMPI )#include "mpi.h" /* Needed for PMPI routines */#else#include "mpi_null.h"#endif /* Endof if !defined( CLOG_NOMPI ) */#include "clog.h"#include "clog_const.h"#include "clog_util.h"#include "clog_timer.h"#include "clog_sync.h"#include "clog_commset.h"/* we want to use the PMPI routines instead of the MPI routines for all of the logging calls internal to the mpe_log package */#ifdef USE_PMPI#define MPI_BUILD_PROFILING#include "mpiprof.h"#endifextern CLOG_Uuid_t CLOG_UUID_NULL;/* Global variables for MPE logging */ CLOG_Stream_t *CLOG_Stream = NULL; CLOG_Buffer_t *CLOG_Buffer = NULL;MPEU_DLL_SPEC CLOG_CommSet_t *CLOG_CommSet = NULL; int MPE_Log_hasBeenInit = 0; int MPE_Log_hasBeenClosed = 0;/*@ MPE_Init_log - Initialize the logging of events. Notes: This routine must be called before any of the other MPE logging routines. It is a collective call over 'MPI_COMM_WORLD'. MPE_Init_log() & MPE_Finish_log() are NOT needed when liblmpe.a is linked because MPI_Init() would have called MPE_Init_log() already. liblmpe.a will be included in the link path if either "mpicc -mpe=mpilog" or "mpecc -mpilog" is used in the link step. This function is threadsafe, but MPE_Init_log() is expected to be called on only one thread in each process. This thread will be labelled as main thread. Returns: Always return MPE_LOG_OK..seealso: MPE_Finish_log()@*/int MPE_Init_log( void ){ MPE_LOG_THREADSTM_DECL#if !defined( CLOG_NOMPI ) int flag; PMPI_Initialized(&flag); if (!flag) { fprintf( stderr, __FILE__":MPE_Init_log() - **** WARNING ****!\n" "\tMPI_Init() has not been called before MPE_Init_log()!\n" "\tMPE logging will call MPI_Init() to get things going.\n" "\tHowever, you are see this message because you're likely\n" "\tmaking an error somewhere, e.g. link with wrong MPE\n" "\tlibrary or make incorrect sequence of MPE logging calls." "\tCheck MPE documentation or README for detailed info.\n" ); PMPI_Init( NULL, NULL ); }#else /* Initialize Serial MPI implementation */ PMPI_Init( NULL, NULL );#endif MPE_LOG_THREAD_INIT MPE_LOG_THREADSTM_GET MPE_LOG_THREAD_LOCK if (!MPE_Log_hasBeenInit || MPE_Log_hasBeenClosed) { CLOG_Stream = CLOG_Open(); CLOG_Local_init( CLOG_Stream, NULL ); CLOG_Buffer = CLOG_Stream->buffer; CLOG_CommSet = CLOG_Buffer->commset; MPE_Log_commIDs_intracomm( CLOG_CommSet->IDs4world, THREADID, CLOG_COMM_WORLD_CREATE, CLOG_CommSet->IDs4world ); MPE_Log_commIDs_intracomm( CLOG_CommSet->IDs4world, THREADID, CLOG_COMM_SELF_CREATE, CLOG_CommSet->IDs4self );#if !defined( CLOG_NOMPI ) /* Leave these on so the clog2 file can be distinguished if real MPI(i.e. non serial-MPI) is used or not. */ if ( CLOG_Buffer->world_rank == 0 ) { CLOG_Buffer_save_constdef( CLOG_Buffer, CLOG_CommSet->IDs4world, THREADID, CLOG_EVT_CONST, MPI_PROC_NULL, "MPI_PROC_NULL" ); CLOG_Buffer_save_constdef( CLOG_Buffer, CLOG_CommSet->IDs4world, THREADID, CLOG_EVT_CONST, MPI_ANY_SOURCE, "MPI_ANY_SOURCE" ); CLOG_Buffer_save_constdef( CLOG_Buffer, CLOG_CommSet->IDs4world, THREADID, CLOG_EVT_CONST, MPI_ANY_TAG, "MPI_ANY_TAG" ); }#endif MPE_Log_hasBeenInit = 1; /* set MPE_Log as being initialized */ MPE_Log_hasBeenClosed = 0; } /* Invoke non-threadsafe version of MPE_Start_log() */ CLOG_Buffer->status = CLOG_INIT_AND_ON; MPE_LOG_THREAD_UNLOCK return MPE_LOG_OK;}/*@ MPE_Start_log - Start the logging of events. Notes: This function is threadsafe.@*/int MPE_Start_log( void ){ MPE_LOG_THREAD_LOCK if (!MPE_Log_hasBeenInit) return MPE_LOG_NOT_INITIALIZED; CLOG_Buffer->status = CLOG_INIT_AND_ON; MPE_LOG_THREAD_UNLOCK return MPE_LOG_OK;}/*@ MPE_Stop_log - Stop the logging of events Notes: This function is threadsafe.@*/int MPE_Stop_log( void ){ MPE_LOG_THREAD_LOCK if (!MPE_Log_hasBeenInit) return MPE_LOG_NOT_INITIALIZED; CLOG_Buffer->status = CLOG_INIT_AND_OFF; MPE_LOG_THREAD_UNLOCK return MPE_LOG_OK;}/*@ MPE_Initialized_logging - Indicate whether MPE_Init_log() or MPE_Finish_log() have been called. Notes: This function is threadsafe. Returns: 0 if MPE_Init_log() has not been called, 1 if MPE_Init_log() has been called but MPE_Finish_log() has not been called, and 2 otherwise.@*/int MPE_Initialized_logging( void ){ return MPE_Log_hasBeenInit + MPE_Log_hasBeenClosed;}/* The is to log CLOG intracommunicator event (Internal MPE routine) This function is NOT threadsafe.*/int MPE_Log_commIDs_intracomm( const CLOG_CommIDs_t *commIDs, int local_thread, int comm_etype, const CLOG_CommIDs_t *intracommIDs ){ CLOG_Buffer_save_commevt( CLOG_Buffer, commIDs, local_thread, comm_etype, intracommIDs->global_ID, intracommIDs->local_ID, intracommIDs->comm_rank, intracommIDs->world_rank ); return MPE_LOG_OK;}/* The is to log CLOG Null communicator event (Internal MPE routine) This function is NOT threadsafe.*/int MPE_Log_commIDs_nullcomm( const CLOG_CommIDs_t *commIDs, int local_thread, int comm_etype ){ CLOG_Buffer_save_commevt( CLOG_Buffer, commIDs, local_thread, comm_etype, CLOG_UUID_NULL, CLOG_COMM_LID_NULL, CLOG_COMM_RANK_NULL, CLOG_COMM_WRANK_NULL ); return MPE_LOG_OK;}/* The is to log CLOG intercommunicator event (Internal MPE routine) This function is NOT threadsafe.*/int MPE_Log_commIDs_intercomm( const CLOG_CommIDs_t *commIDs, int local_thread, int comm_etype, const CLOG_CommIDs_t *intercommIDs ){ CLOG_CommIDs_t *local_intracommIDs; CLOG_CommIDs_t *remote_intracommIDs; CLOG_Buffer_save_commevt( CLOG_Buffer, commIDs, local_thread, comm_etype, intercommIDs->global_ID, intercommIDs->local_ID, intercommIDs->comm_rank, intercommIDs->world_rank ); /* Don't check for local_intracommIDs = NULL or remote_intracommIDs = NULL prefer sigfault than fail silently. */ local_intracommIDs = intercommIDs->next; CLOG_Buffer_save_commevt( CLOG_Buffer, commIDs, local_thread, CLOG_COMM_INTRA_LOCAL, local_intracommIDs->global_ID, local_intracommIDs->local_ID, local_intracommIDs->comm_rank, local_intracommIDs->world_rank ); remote_intracommIDs = local_intracommIDs->next; CLOG_Buffer_save_commevt( CLOG_Buffer, commIDs, local_thread, CLOG_COMM_INTRA_REMOTE, remote_intracommIDs->global_ID, remote_intracommIDs->local_ID, remote_intracommIDs->comm_rank, remote_intracommIDs->world_rank ); return MPE_LOG_OK;}/*N MPE_LOG_BYTE_FORMAT Notes on storage format control support: The format control string is printf like, e.g. "Comment = %s". All the MPE %-token storage support is provided by SLOG-2. That is whatever supported by SLOG-2 will be supported by MPE. Currently, the following is supported. %s : variable length string, byte buffer size is length of string + 2. %h : 2-byte integer, printed as decimal integer, byte buffer size is 2. %d : 4-byte integer, printed as decimal integer, byte buffer size is 4. %l : 8-byte integer, printed as decimal integer, byte buffer size is 8. %x : 4-byte integer, printed as hexadecimal integer, byte buffer size is 4. %X : 8-byte integer, printed as hexadecimal integer, byte buffer size is 8. %e : 4-byte float, printed as decimal float, byte buffer size is 4. %E : 8-byte float, printed as decimal float, byte buffer size is 8..nN*//*@ MPE_Describe_comm_state - Describe attributes of a state with byte informational data in a specified MPI_Comm and on the thread that the function is invoked. Input Parameters:+ comm - MPI_Comm where this process is part of.. state_startID - event number for the starting of the state.. state_finalID - event number for the ending of the state.. name - name of the state, the maximum length of the NULL-terminated string is, sizeof(CLOG_DESC), 32.. color - color of the state, the maximum length of the NULL-terminated string is, sizeof(CLOG_COLOR), 24.- format - printf style %-token format control string for the state, the maximum length of the NULL-terminated string is, sizeof(CLOG_FORMAT), 40. If format is NULL, it is equivalent to calling MPE_Describe_state(). The fortran interface of this routine considers the zero-length string, "", and single-blank string, " ", as NULL. Notes: Adds a state definition to the logfile. States are added to a logfile by calling 'MPE_Log_comm_event()' for the start and end event numbers. This function is threadsafe..N MPE_LOG_BYTE_FORMAT.seealso: MPE_Log_get_state_eventIDs()@*/int MPE_Describe_comm_state( MPI_Comm comm, int state_startID, int state_finalID, const char *name, const char *color, const char *format ){ const CLOG_CommIDs_t *commIDs; int stateID; MPE_LOG_THREADSTM_DECL MPE_LOG_THREADSTM_GET MPE_LOG_THREAD_LOCK if (!MPE_Log_hasBeenInit) return MPE_LOG_NOT_INITIALIZED; commIDs = CLOG_CommSet_get_IDs( CLOG_CommSet, comm ); stateID = CLOG_Get_user_stateID( CLOG_Stream ); CLOG_Buffer_save_statedef( CLOG_Buffer, commIDs, THREADID, stateID, state_startID, state_finalID, color, name, format ); MPE_LOG_THREAD_UNLOCK return MPE_LOG_OK;}/*@ MPE_Describe_info_state - Describe attributes of a state with byte informational data in MPI_COMM_WORLD. Input Parameters:+ state_startID - event number for the beginning of the state.. state_finalID - event number for the ending of the state.. name - name of the state, the maximum length of the NULL-terminated string is, sizeof(CLOG_DESC), 32.. color - color of the state, the maximum length of the NULL-terminated string is, sizeof(CLOG_COLOR), 24.- format - printf style %-token format control string for the state, the maximum length of the NULL-terminated string is, sizeof(CLOG_FORMAT), 40. If format is NULL, it is equivalent to calling MPE_Describe_state(). The fortran interface of this routine considers the zero-length string, "", and single-blank string, " ", as NULL. Notes: Adds a state definition to the logfile. States are added to a logfile by calling 'MPE_Log_event()' for the start and end event numbers. The function is provided for backward compatibility purpose. Users are urged to use 'MPE_Describe_comm_state' and 'MPE_Log_comm_event()' instead. This function is threadsafe..N MPE_LOG_BYTE_FORMAT.seealso: MPE_Log_get_state_eventIDs().@*/int MPE_Describe_info_state( int state_startID, int state_finalID, const char *name, const char *color, const char *format ){ return MPE_Describe_comm_state( MPI_COMM_WORLD, state_startID, state_finalID, name, color, format );}/* This is a MPE internal function to describe MPI states. It is not meant for user application. stateID should be fetched from CLOG_Get_known_stateID() i.e, MPE_Log_get_known_stateID() This function is NOT threadsafe.*/int MPE_Describe_known_state( const CLOG_CommIDs_t *commIDs, int local_thread, int stateID, int state_startID, int state_finalID, const char *name, const char *color, const char *format ){ if (!MPE_Log_hasBeenInit) return MPE_LOG_NOT_INITIALIZED; if ( CLOG_Check_known_stateID( CLOG_Stream, stateID ) != CLOG_BOOL_TRUE ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -