20 #ifndef TIMPI_TIMPI_ASSERT_H 21 #define TIMPI_TIMPI_ASSERT_H 24 #include "timpi/timpi_config.h" 30 #include <type_traits> 34 #ifdef TIMPI_ENABLE_TIMESTAMPS 35 # define TIMPI_TIME __TIME__ 36 # define TIMPI_DATE __DATE__ 38 # define TIMPI_TIME "notime" 39 # define TIMPI_DATE "nodate" 48 void report_here(
const char * file,
int line,
const char * date,
const char * time);
49 void report_error(
const char * file,
int line,
const char * date,
const char * time);
54 template<
class ...Args>
inline void ignore(
const Args&... ) { }
59 #define timpi_dbg_var(var) var 61 #define timpi_dbg_var(var) 68 #define timpi_assert_msg(asserted, msg) ((void) 0) 69 #define timpi_assert_equal_to_msg(expr1,expr2, msg) ((void) 0) 70 #define timpi_assert_not_equal_to_msg(expr1,expr2, msg) ((void) 0) 71 #define timpi_assert_less_msg(expr1,expr2, msg) ((void) 0) 72 #define timpi_assert_greater_msg(expr1,expr2, msg) ((void) 0) 73 #define timpi_assert_less_equal_msg(expr1,expr2, msg) ((void) 0) 74 #define timpi_assert_greater_equal_msg(expr1,expr2, msg) ((void) 0) 78 #define timpi_assert_msg(asserted, msg) \ 81 std::cerr << "Assertion `" #asserted "' failed." << std::endl; \ 82 timpi_error_msg(msg); \ 85 #define timpi_assert_equal_to_msg(expr1,expr2, msg) \ 87 if (!((expr1) == (expr2))) { \ 88 std::cerr << "Assertion `" #expr1 " == " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 92 #define timpi_assert_not_equal_to_msg(expr1,expr2, msg) \ 94 if (!((expr1) != (expr2))) { \ 95 std::cerr << "Assertion `" #expr1 " != " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 101 #if defined(__clang__) && (__clang_major__ <= 3) 103 #define timpi_assert_less_msg(expr1,expr2, msg) \ 105 if (!((expr1) < (expr2))) { \ 106 std::cerr << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 110 #define timpi_assert_greater_msg(expr1,expr2, msg) \ 112 if (!((expr1) > (expr2))) { \ 113 std::cerr << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 117 #define timpi_assert_less_equal_msg(expr1,expr2, msg) \ 119 if (!((expr1) <= (expr2))) { \ 120 std::cerr << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 124 #define timpi_assert_greater_equal_msg(expr1,expr2, msg) \ 126 if (!((expr1) >= (expr2))) { \ 127 std::cerr << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 134 template <
template <
class>
class Comp>
137 template <
typename T1,
typename T2>
140 typedef typename std::decay<T1>::type DT1;
141 typedef typename std::decay<T2>::type DT2;
142 return (Comp<DT2>()(static_cast<DT2>(e1), e2) &&
143 Comp<DT1>()(e1, static_cast<DT1>(e2)));
146 template <
typename T1>
149 return Comp<T1>()(e1, e2);
153 #define timpi_assert_less_msg(expr1,expr2, msg) \ 155 if (!TIMPI::casting_compare<std::less>()(expr1, expr2)) { \ 156 std::cerr << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 160 #define timpi_assert_greater_msg(expr1,expr2, msg) \ 162 if (!TIMPI::casting_compare<std::greater>()(expr1, expr2)) { \ 163 std::cerr << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 167 #define timpi_assert_less_equal_msg(expr1,expr2, msg) \ 169 if (!TIMPI::casting_compare<std::less_equal>()(expr1, expr2)) { \ 170 std::cerr << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 174 #define timpi_assert_greater_equal_msg(expr1,expr2, msg) \ 176 if (!TIMPI::casting_compare<std::greater_equal>()(expr1, expr2)) { \ 177 std::cerr << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \ 186 #define timpi_assert(asserted) timpi_assert_msg(asserted, "") 187 #define timpi_assert_equal_to(expr1,expr2) timpi_assert_equal_to_msg(expr1,expr2, "") 188 #define timpi_assert_not_equal_to(expr1,expr2) timpi_assert_not_equal_to_msg(expr1,expr2, "") 189 #define timpi_assert_less(expr1,expr2) timpi_assert_less_msg(expr1,expr2, "") 190 #define timpi_assert_greater(expr1,expr2) timpi_assert_greater_msg(expr1,expr2, "") 191 #define timpi_assert_less_equal(expr1,expr2) timpi_assert_less_equal_msg(expr1,expr2, "") 192 #define timpi_assert_greater_equal(expr1,expr2) timpi_assert_greater_equal_msg(expr1,expr2, "") 199 #define timpi_parallel_only(comm_obj) do { \ 200 timpi_assert_msg((comm_obj).verify(std::string(__FILE__).length()), \ 201 "Different ranks are at different timpi_parallel_only points"); \ 202 timpi_assert_msg((comm_obj).verify(std::string(__FILE__)), \ 203 "Different ranks are at different timpi_parallel_only points"); \ 204 timpi_assert_msg((comm_obj).verify(__LINE__), \ 205 "Different ranks are at different timpi_parallel_only points"); \ 208 #define timpi_parallel_only(comm_obj) ((void) 0) 212 #ifdef TIMPI_ENABLE_EXCEPTIONS 213 #define TIMPI_THROW(e) do { throw e; } while (0) 215 #define TIMPI_THROW(e) do { std::abort(); } while (0) 224 #define timpi_error_msg(msg) \ 226 std::cerr << msg << std::endl; \ 227 std::stringstream msg_stream; \ 229 TIMPI::report_error(__FILE__, __LINE__, TIMPI_DATE, TIMPI_TIME); \ 230 TIMPI_THROW(std::logic_error(msg_stream.str())); \ 233 #define timpi_error() timpi_error_msg("") 235 #define timpi_not_implemented_msg(msg) \ 237 std::cerr << msg << std::endl; \ 238 TIMPI::report_error(__FILE__, __LINE__, TIMPI_DATE, TIMPI_TIME); \ 239 TIMPI_THROW(std::logic_error("Error: not implemented!")); \ 242 #define timpi_not_implemented() timpi_not_implemented_msg("") 247 #define timpi_do_once(do_this) \ 249 static bool did_this_already = false; \ 250 if (!did_this_already) { \ 251 did_this_already = true; \ 258 #ifdef TIMPI_ENABLE_WARNINGS 259 #define timpi_warning(message) \ 260 timpi_do_once(std::cout << message \ 261 << __FILE__ << ", line " << __LINE__ << ", compiled " << TIMPI_DATE << " at " << TIMPI_TIME << " ***" << std::endl;) 263 #define timpi_warning(message) ((void) 0) 268 #undef timpi_experimental 269 #define timpi_experimental() \ 270 timpi_warning("*** Warning, This code is untested, experimental, or likely to see future API changes: "); 274 #undef timpi_deprecated 275 #ifndef TIMPI_ENABLE_DEPRECATED 276 #define timpi_deprecated() \ 277 timpi_error_msg("*** Error, This code is deprecated, and likely to be removed in future library versions! "); 279 #define timpi_deprecated() \ 280 timpi_warning("*** Warning, This code is deprecated, and likely to be removed in future library versions! "); 296 template <
typename Tnew,
typename Told>
299 timpi_assert_equal_to
300 (oldvar, static_cast<Told>(static_cast<Tnew>(oldvar)));
302 return(static_cast<Tnew>(oldvar));
308 #endif // TIMPI_TIMPI_ASSERT_H void ignore(const Args &...)
void report_error(const char *file, int line, const char *date, const char *time)
bool operator()(const T1 &e1, const T1 &e2) const
void timpi_ignore(const Args &...)
void report_here(const char *file, int line, const char *date, const char *time)
bool operator()(const T1 &e1, const T2 &e2) const
Tnew cast_int(Told oldvar)