Skip to content

Commit

Permalink
removed global state
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelyr committed Nov 30, 2024
1 parent 6cfaf55 commit e84fbe2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(SOURCES
ppTiming.cpp
ppAssert.cpp
ViewComm.cpp
ppPrint.cpp
)

add_library(support ${SOURCES})
Expand Down
20 changes: 20 additions & 0 deletions support/ppPrint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "ppPrint.h"

namespace pumipic {

FILE* pp_stdout = stdout;
FILE* pp_stderr = stderr;

FILE* getStdout() { return pp_stdout; }
FILE* getStderr() { return pp_stderr; }

void setStdout(FILE* out) {
assert(out != NULL);
pp_stdout = out;
}

void setStderr(FILE* err) {
assert(err != NULL);
pp_stderr = err;
}
}
19 changes: 6 additions & 13 deletions support/ppPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,18 @@ namespace pumipic {
#define ACTIVE_GPU_EXECUTION
#endif

inline FILE* pp_stdout = stdout;
inline FILE* pp_stderr = stderr;
FILE* getStdout();
FILE* getStderr();

inline void setStdout(FILE* out) {
assert(out != NULL);
pp_stdout = out;
}

inline void setStderr(FILE* err) {
assert(err != NULL);
pp_stderr = err;
}
void setStdout(FILE* out);
void setStderr(FILE* err);

template<typename... Args>
void printError(std::string fmt, const Args&... args) {
#if defined(PUMIPIC_SPDLOG_ENABLED) && defined(PUMIPIC_PRINT_ENABLED)
spdlog::error("{}", fmt::sprintf(fmt, args...));
#elif defined(PUMIPIC_PRINT_ENABLED)
fprintf(pp_stderr, ("[ERROR]"+fmt).c_str(), args...);
fprintf(getStderr(), ("[ERROR]"+fmt).c_str(), args...);
#endif
}

Expand All @@ -43,7 +36,7 @@ namespace pumipic {
#if defined(PUMIPIC_SPDLOG_ENABLED) && defined(PUMIPIC_PRINT_ENABLED) && !defined(ACTIVE_GPU_EXECUTION)
spdlog::info("{}", fmt::sprintf(fmt, args...));
#elif defined(PUMIPIC_PRINT_ENABLED) && !defined(ACTIVE_GPU_EXECUTION)
fprintf(pp_stdout, fmt, args...);
fprintf(getStdout(), fmt, args...);
#endif
}

Expand Down

0 comments on commit e84fbe2

Please sign in to comment.