19#include <fmt/ostream.h>
21#include <amdis/Environment.hpp>
22#include <amdis/common/TypeTraits.hpp>
33#ifndef AMDIS_ENABLE_MSG_DBG
35 #define AMDIS_ENABLE_MSG_DBG 1
37 #define AMDIS_ENABLE_MSG_DBG 0
41#define AMDIS_FUNCNAME(nn) [[maybe_unused]] const char *funcName = nn;
44 #define AMDIS_FUNCNAME_DBG(nn)
45 #define AMDIS_DBG_VAR(var)
47 #define AMDIS_FUNCNAME_DBG(nn) [[maybe_unused]] const char *funcName = nn;
48 #define AMDIS_DBG_VAR(var) var
56 template <
class OStream,
class... Args>
57 OStream& msg_all(OStream& out, std::string
const& str, Args&&... args)
60 fmt::print(out, fmt::runtime(
"[" + std::to_string(
Environment::mpiRank()) +
"] " + str), FWD(args)...);
62 fmt::print(out, fmt::runtime(str), FWD(args)...);
66 template <
class OStream,
class... Args>
67 OStream& msg(OStream& out, std::string
const& str, Args&&... args)
70 return msg_all(out, str, FWD(args)...);
73 fmt::print(out, fmt::runtime(
"[0] " + str), FWD(args)...);
75 fmt::print(out, fmt::runtime(str), FWD(args)...);
80 void printType (T
const&)
82 std::cout << __PRETTY_FUNCTION__ << std::endl;
88 std::cout << __PRETTY_FUNCTION__ << std::endl;
101 template <
class... Args>
102 void msg(std::string
const& str, Args&&... args)
104 Impl::msg(std::cout, str +
"\n", FWD(args)...);
108 template <
class... Args>
109 void info(
int noInfoLevel, std::string
const& str, Args&&... args)
112 Impl::msg(std::cout, str +
"\n", FWD(args)...);
123 template <
class... Args>
124 void msg_(std::string
const& str, Args&&... args)
126 Impl::msg(std::cout, str, FWD(args)...);
130 template <
class... Args>
131 void info_(
int noInfoLevel, std::string
const& str, Args&&... args)
134 Impl::msg(std::cout, str, FWD(args)...);
145 template <
class... Args>
146 void error_exit(std::string
const& str, Args&&... args)
149 Impl::msg_all(std::cerr,
"ERROR: " + str +
"\n", FWD(args)...);
152 throw std::runtime_error( std::string(
"ERROR: ") + fmt::format(fmt::runtime(str), FWD(args)...));
166 template <
class... Args>
167 void test_exit(
bool condition, std::string
const& str, Args&&... args)
169 if (!condition) { error_exit(str, FWD(args)...); }
173 template <
class... Args>
174 void warning(std::string
const& str, Args&&... args)
176 Impl::msg(std::cout,
"WARNING: " + str +
"\n", FWD(args)...);
186 template <
class... Args>
187 void test_warning(
bool condition, std::string
const& str, Args&&... args)
189 if (!condition) { warning(str, FWD(args)...); }
193#if AMDIS_ENABLE_MSG_DBG
199 template <
class... Args>
200 void msg_dbg(Args&&... args) { msg(FWD(args)...); }
208 template <
class... Args>
209 void test_exit_dbg(
bool condition, Args&&... args)
211 test_exit(condition, FWD(args)...);
214 template <
class... Args>
215 void msg_dbg(Args&&...) {}
217 template <
class... Args>
218 void test_exit_dbg(
bool, Args&&...) {}
static int mpiSize()
Return the MPI_Size of the group created by Dune::MPIHelper.
Definition: Environment.hpp:74
static int infoLevel()
Return the info level for messages in info()
Definition: Environment.cpp:63
static int mpiRank()
Return the MPI_Rank of the current processor.
Definition: Environment.hpp:68
static bool msgAllRanks()
Return whether all ranks print msg()
Definition: Environment.cpp:71