Logger

Example of a log entry:

15:10:35:639  Rank 0000    INFO at /Mirheo/src/mirheo/core/logger.cpp:54 Compiled with maximum debug level 10
15:10:35:640  Rank 0000    INFO at /Mirheo/src/mirheo/core/logger.cpp:56 Debug level requested 3, set to 3
15:10:35:640  Rank 0000    INFO at /Mirheo/src/mirheo/core/mirheo.cpp:110 Program started, splitting communicator
15:10:35:684  Rank 0000    INFO at /Mirheo/src/mirheo/core/mirheo.cpp:58 Detected 1 ranks per node, my intra-node ID will be 0
15:10:35:717  Rank 0000    INFO at /Mirheo/src/mirheo/core/mirheo.cpp:65 Found 1 GPUs per node, will use GPU 0

API

class Logger

logging functionality with MPI support.

Each MPI process writes to its own file, prefixing messages with time stamps so that later the information may be combined and sorted. Filenames have the following pattern, NNNNN is the MPI rank with leading zeros: <common_name>_NNNNN.log

Debug level governs which messages to log will be printed (a higher level will dump more log messages).

Every logging call has an importance level associated with it, which is compared against the governing debug level, e.g. debug() importance is 4 and error() importance is 1.

Logger logger;
has to be defined in one the objective file (typically the one that contains main()). Prior to any logging the method init() must be called.

Public Functions

Logger()

Initialize the logger.

Experimental: logger can be automatically set to output to stdout by settings the MIRHEO_LOGGER_AUTO_STDOUT environment variable to a non-zero value. This is useful in multi-library contexts where multiple loggers may be created.

void init(MPI_Comm comm, const std::string &filename, int debugLvl = -1)

Setup the logger object.

Must be called before any logging method.

Parameters
  • comm: MPI communicator that contains all ranks that will use the logger. If set to MPI_COMM_NULL, the logger does not require MPI to be initialized.
  • filename: log files will be prefixed with filename: e.g. filename_<rank_with_leading_zeros>.log
  • debugLvl: debug level or -1 to use the default value

void init(MPI_Comm comm, FileWrapper fout, int debugLvl = -1)

Setup the logger object to write to a given file.

Parameters
  • comm: MPI communicator that contains all ranks that will use the logger. If set to MPI_COMM_NULL, the logger does not require MPI to be initialized.
  • fout: file handler, must be open, typically stdout or stderr
  • debugLvl: debug leve or -1 to use the default value

int getDebugLvl() const

return The current debug level

void setDebugLvl(int debugLvl)

set the debug level

Parameters
  • debugLvl: debug level

void log(const char *key, const char *filename, int line, const char *pattern, ...) const

Main logging function.

Construct and dump a log entry with time prefix, importance string, filename and line number, and the message itself.

This function is not supposed to be called directly, use appropriate macros instead, e.g. say(), error(), debug().

Warning

When the debug level is higher or equal to the c flushThreshold_ member variable (default 8), every message is flushed to disk immediately. This may increase the runtime significantly and only recommended to debug crashes.

Parameters
  • key: The importance string, e.g. LOG or WARN
  • filename: name of the current source file
  • line: line number in the current source file
  • pattern: message pattern to be passed to printf

void _die(const char *filename, int line, const char *fmt, ...) const

Calls log() and kills the application on a fatal error.

Print stack trace, error message, close the file and abort. See log() for parameters.

void _CUDA_die(const char *filename, int line, cudaError_t code) const

Calls _die() with the error message corresponding to the given CUDA error code.

Parameters
  • filename: name of the current source file
  • line: line number in the current source file
  • code: CUDA error code (returned by a CUDA call)

void _MPI_die(const char *filename, int line, int code) const

Calls _die() with the error message corresponding to the given MPI error code.

Parameters
  • filename: name of the current source file
  • line: line number in the current source file
  • code: MPI error code (returned by an MPI call)

void _CUDA_Check(const char *filename, const int line, cudaError_t code) const

check a CUDA error call and call _CUDA_die() in case of error

void _MPI_Check(const char *filename, const int line, const int code) const

check an MPI error call and call _MPI_die() in case of error