Quandary
Loading...
Searching...
No Matches
mpi_logger.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4#include <iostream>
5
12class MPILogger {
13 private:
14 int mpi_rank;
15 bool quiet_mode;
16
17 public:
24 MPILogger(int rank, bool quiet = false) : mpi_rank(rank), quiet_mode(quiet) {}
25
31 void log(const std::string& message) const {
32 if (!quiet_mode && mpi_rank == 0) {
33 std::cout << message << std::endl;
34 }
35 }
36
42 void error(const std::string& message) const {
43 if (mpi_rank == 0) {
44 std::cerr << "ERROR: " << message << std::endl;
45 }
46 }
47
53 [[noreturn]]
54 void exitWithError(const std::string& message) const {
55 error(message);
56 exit(1);
57 }
58};
MPI-aware logger that handles rank filtering and quiet mode.
Definition mpi_logger.hpp:12
void exitWithError(const std::string &message) const
Logs an error and terminates the program.
Definition mpi_logger.hpp:54
void log(const std::string &message) const
Logs a message to stdout (rank 0 only, respects quiet mode).
Definition mpi_logger.hpp:31
void error(const std::string &message) const
Logs an error message to stderr (rank 0 only).
Definition mpi_logger.hpp:42
MPILogger(int rank, bool quiet=false)
Constructs an MPI logger.
Definition mpi_logger.hpp:24