Skip to content

Commit a1b9cf2

Browse files
committed
Merge pull request #177 from torbjoernk/feature/mpi-logging-improve
add MPI rank to logging output (iff MPI enabled)
2 parents 9d83617 + 7090b2b commit a1b9cf2

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

include/pfasst/logging.hpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
using namespace std;
1313

1414
#ifdef WITH_MPI
15+
#include <iomanip>
16+
#include <sstream>
17+
1518
#include <mpi.h>
1619
#endif
1720

@@ -205,10 +208,23 @@ namespace pfasst
205208
inline static void add_custom_logger(const string& id)
206209
{
207210
const string TIMESTAMP = OUT::white + "%datetime{%H:%m:%s,%g}" + OUT::reset + " ";
208-
const string LEVEL = "%level]";
209-
const string VLEVEL = "VERB%vlevel]";
211+
const string LEVEL = "%level";
212+
const string VLEVEL = "VERB%vlevel";
210213
const string POSITION = "%fbase:%line";
211214
const string MESSAGE = "%msg";
215+
#ifdef WITH_MPI
216+
int initialized = 0;
217+
MPI_Initialized(&initialized);
218+
assert((bool)initialized);
219+
int rank = 0;
220+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
221+
222+
ostringstream frmter;
223+
frmter << std::setw(3) << rank;
224+
const string MPI_RANK = ", rank " + frmter.str();
225+
#else
226+
const string MPI_RANK = "";
227+
#endif
212228

213229
const string INFO_COLOR = OUT::blue;
214230
const string DEBG_COLOR = "";
@@ -235,28 +251,24 @@ namespace pfasst
235251
conf->setGlobally(el::ConfigurationType::ToStandardOutput,
236252
default_conf->get(el::Level::Info,
237253
el::ConfigurationType::ToStandardOutput)->value());
254+
238255
#ifdef WITH_MPI
239-
int initialized = 0;
240-
MPI_Initialized(&initialized);
241-
assert((bool)initialized);
242-
int rank = 0;
243-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
244256
conf->setGlobally(el::ConfigurationType::ToFile, "true");
245257
conf->setGlobally(el::ConfigurationType::Filename,
246258
string("mpi_run_") + to_string(rank) + string(".log"));
247259
#endif
248260
conf->set(el::Level::Info, el::ConfigurationType::Format,
249-
TIMESTAMP + INFO_COLOR + "[" + id2print + ", " + LEVEL + " " + MESSAGE + OUT::reset);
261+
TIMESTAMP + INFO_COLOR + "[" + id2print + ", " + LEVEL + MPI_RANK + "] " + MESSAGE + OUT::reset);
250262
conf->set(el::Level::Debug, el::ConfigurationType::Format,
251-
TIMESTAMP + DEBG_COLOR + "[" + id2print + ", " + LEVEL + " " + POSITION + " " + MESSAGE + OUT::reset);
263+
TIMESTAMP + DEBG_COLOR + "[" + id2print + ", " + LEVEL + MPI_RANK + "] " + POSITION + " " + MESSAGE + OUT::reset);
252264
conf->set(el::Level::Warning, el::ConfigurationType::Format,
253-
TIMESTAMP + WARN_COLOR + "[" + id2print + ", " + LEVEL + " " + MESSAGE + OUT::reset);
265+
TIMESTAMP + WARN_COLOR + "[" + id2print + ", " + LEVEL + MPI_RANK + "] " + MESSAGE + OUT::reset);
254266
conf->set(el::Level::Error, el::ConfigurationType::Format,
255-
TIMESTAMP + ERRO_COLOR + "[" + id2print + ", " + LEVEL + " " + MESSAGE + OUT::reset);
267+
TIMESTAMP + ERRO_COLOR + "[" + id2print + ", " + LEVEL + MPI_RANK + "] " + MESSAGE + OUT::reset);
256268
conf->set(el::Level::Fatal, el::ConfigurationType::Format,
257-
TIMESTAMP + FATA_COLOR + "[" + id2print + ", " + LEVEL + " " + POSITION + " " + MESSAGE + OUT::reset);
269+
TIMESTAMP + FATA_COLOR + "[" + id2print + ", " + LEVEL + MPI_RANK + "] " + POSITION + " " + MESSAGE + OUT::reset);
258270
conf->set(el::Level::Verbose, el::ConfigurationType::Format,
259-
TIMESTAMP + VERB_COLOR + "[" + id2print + ", " + VLEVEL + " " + MESSAGE + OUT::reset);
271+
TIMESTAMP + VERB_COLOR + "[" + id2print + ", " + VLEVEL + MPI_RANK + "] " + MESSAGE + OUT::reset);
260272
el::Loggers::reconfigureLogger(logger, *conf);
261273
}
262274

0 commit comments

Comments
 (0)