Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/reference/idefix.ini.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ This section describes the outputs *Idefix* produces. For more details about eac
+================+=========================+==================================================================================================+
| log | integer | | Time interval between log outputs, in code steps (default 100). |
+----------------+-------------------------+--------------------------------------------------------------------------------------------------+
| log_dir | string | | directory for log file outputs. Default to "./" |
| | | | The directory is automatically created if it does not exist. |
+----------------+-------------------------+--------------------------------------------------------------------------------------------------+
| dmp | float, float+char | | 1st parameter: Code time interval between dump outputs, in code units. |
| | | | If negative, the first parameter is ignored. |
| | | | 2nd parameter (optional): Wallclock time interval between two dumps. The ending character |
Expand Down
36 changes: 32 additions & 4 deletions src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
#include <iostream>
#include <string>
#include <sstream>
#if __has_include(<filesystem>)
#include <filesystem> // NOLINT [build/c++17]
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#error "Missing the <filesystem> header."
#endif

#include "idefix.hpp"
#include "global.hpp"
#include "profiler.hpp"
Expand Down Expand Up @@ -105,13 +115,31 @@ void IdefixOutStream::init(int rank) {


// disable the log file
void IdefixOutStream::enableLogFile() {
void IdefixOutStream::enableLogFile(std::string logFileDir) {
std::stringstream sslogFileName;
sslogFileName << "idefix." << idfx::prank << ".log";

sslogFileName << logFileDir << "/" << "idefix." << idfx::prank << ".log";
std::string logFileName(sslogFileName.str());
this->my_fstream.open(logFileName.c_str());

if(idfx::prank==0) {
if(!fs::is_directory(logFileDir)) {
try {
if(!fs::create_directories(logFileDir)) {
std::stringstream msg;
msg << "Cannot create directory " << logFileDir << std::endl;
IDEFIX_ERROR(msg);
}
} catch(std::exception &e) {
std::stringstream msg;
msg << "Cannot create directory " << logFileDir << std::endl;
msg << e.what();
IDEFIX_ERROR(msg);
}
}
}
#ifdef WITH_MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
this->my_fstream.open(logFileName.c_str());
this->logFileEnabled = true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Units;

extern int prank; //< parallel rank
extern int psize;
extern std::string logFileDir; //< logfileDir
extern IdefixOutStream cout; //< custom cout for idefix
extern IdefixErrStream cerr; //< custom cerr for idefix
extern Profiler prof; //< profiler (for memory & performance usage)
Expand Down Expand Up @@ -66,7 +67,7 @@ void DumpArray(std::string filename, ArrayType array) {
class idfx::IdefixOutStream {
public:
void init(int);
void enableLogFile();
void enableLogFile(std::string logFileDir);
// for regular output of variables and stuff
template<typename T> IdefixOutStream& operator<<(const T& something) {
if(toscreen) std::cout << something;
Expand Down
18 changes: 12 additions & 6 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Input::Input(int argc, char* argv[] ) {
bool haveBlock = false;
std::stringstream msg;
int nParameters = 0; // # of parameters in current block
// Log files are enabled by default
this->enableLogs = true;

// Tell the system we want to catch the SIGUSR2 signals
signal(SIGUSR2, signalHandler);
Expand Down Expand Up @@ -109,12 +111,19 @@ Input::Input(int argc, char* argv[] ) {
}
}
file.close();

if(this->enableLogs) {
std::string logFileDir{"./"};
if(CheckEntry("Output","log_dir")>=0) {
logFileDir = Get<std::string>("Output", "log_dir", 0);
}
idfx::cout.enableLogFile(logFileDir);
}
}

// This routine parse command line options
void Input::ParseCommandLine(int argc, char **argv) {
std::stringstream msg;
bool enableLogs = true;
for(int i = 1 ; i < argc ; i++) {
// MPI decomposition argument
if(std::string(argv[i]) == "-dec") {
Expand Down Expand Up @@ -172,9 +181,9 @@ void Input::ParseCommandLine(int argc, char **argv) {
this->forceInitRequested = true;
} else if(std::string(argv[i]) == "-nowrite") {
this->forceNoWrite = true;
enableLogs = false;
this->enableLogs = false;
} else if(std::string(argv[i]) == "-nolog") {
enableLogs = false;
this->enableLogs = false;
} else if(std::string(argv[i]) == "-profile") {
idfx::prof.EnablePerformanceProfiling();
} else if(std::string(argv[i]) == "-Werror") {
Expand All @@ -191,9 +200,6 @@ void Input::ParseCommandLine(int argc, char **argv) {
IDEFIX_ERROR(msg);
}
}
if(enableLogs) {
idfx::cout.enableLogFile();
}
}


Expand Down
3 changes: 3 additions & 0 deletions src/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Input {
Input (int, char ** );
void ShowConfig();

// flag if logging is to be done
bool enableLogs;

// Accessor to input parameters
// the parameters are always: BlockName, EntryName, ParameterNumber (starting from 0)
// These specialised functions are deprecated. Use the template Get<T> function.
Expand Down