Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
throw_assert.hpp File Reference

Declaration of our assertion macros.

Namespaces

namespace  mundy

Concepts

concept  mundy::DevicePrintableThrowMessage

Macros

#define MUNDY_THROW_REQUIRE(assertion_to_test, exception_to_throw, message_to_print)
 Abort the code if the given assertion is false.
#define MUNDY_THROW_ASSERT(assertion_to_test, exception_to_throw, message_to_print)
 Throw an exception if the given assertion is false.

Functions

template<size_t AssertionStringSize, size_t FileStringSize, size_t LineStringSize>
std::string mundy::get_throw_require_host_string (const StringLiteral< AssertionStringSize > &assertion_string, const std::string &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<size_t AssertionStringSize, size_t MessageStringSize, size_t FileStringSize, size_t LineStringSize>
std::string mundy::get_throw_require_host_string (const StringLiteral< AssertionStringSize > &assertion_string, const char(&message_to_print)[MessageStringSize], const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<size_t AssertionStringSize, size_t MessageStringSize, size_t FileStringSize, size_t LineStringSize>
std::string mundy::get_throw_require_host_string (const StringLiteral< AssertionStringSize > &assertion_string, const StringLiteral< MessageStringSize > &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<size_t AssertionStringSize, AnyStringSink MessageStringType, size_t FileStringSize, size_t LineStringSize>
std::string mundy::get_throw_require_host_string (const StringLiteral< AssertionStringSize > &assertion_string, const MessageStringType &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<size_t AssertionStringSize, size_t MessageStringSize, size_t FileStringSize, size_t LineStringSize>
constexpr auto mundy::get_throw_require_device_string (const StringLiteral< AssertionStringSize > &assertion_string, const char(&message_to_print)[MessageStringSize], const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<size_t AssertionStringSize, size_t MessageStringSize, size_t FileStringSize, size_t LineStringSize>
constexpr auto mundy::get_throw_require_device_string (const StringLiteral< AssertionStringSize > &assertion_string, const StringLiteral< MessageStringSize > &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<size_t AssertionStringSize, CompileTimeStringSink MessageStringType, size_t FileStringSize, size_t LineStringSize>
constexpr auto mundy::get_throw_require_device_string (const StringLiteral< AssertionStringSize > &assertion_string, const MessageStringType &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<typename ExceptionType, typename MessageStringType, size_t AssertionStringSize, size_t FileStringSize, size_t LineStringSize>
constexpr void mundy::throw_require (const bool assertion_value, const StringLiteral< AssertionStringSize > &assertion_string, const MessageStringType &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))
template<typename MessageStringType, size_t AssertionStringSize, size_t FileStringSize, size_t LineStringSize>
constexpr void mundy::abort_require (const bool assertion_value, const StringLiteral< AssertionStringSize > &assertion_string, const MessageStringType &message_to_print, const StringLiteral< FileStringSize > &file_string=make_string_literal("/home/runner/work/MuNDy/MuNDy/mundy/core/utils/src/mundy_utils/throw_assert.hpp"), const StringLiteral< LineStringSize > &line_string=make_string_literal(MUNDY_LINE_STRING))

Macro Definition Documentation

◆ MUNDY_THROW_REQUIRE

#define MUNDY_THROW_REQUIRE ( assertion_to_test,
exception_to_throw,
message_to_print )
Value:
do { \
KOKKOS_IF_ON_HOST(MUNDY_THROW_REQUIRE_HOST(assertion_to_test, exception_to_throw, message_to_print);) \
KOKKOS_IF_ON_DEVICE(MUNDY_THROW_REQUIRE_DEVICE(assertion_to_test, exception_to_throw, message_to_print);) \
} while (false);
Note
This macro will always test the assertion, regardless of whether NDEBUG is defined. Use it to enforce critical requirements (hence the name).

Host and device compatible. The two differ heavily in that host can print the function name, while device cannot. The host code will throw the given exception, while the device code will abort. The abort is unavoidable, as device code cannot throw exceptions.

Message types: On the host, the message may be a string literal, std::string, mundy::StringLiteral, or a sink expression such as mundy::sink() << "Failure for a = " << a. On the device, only compile-time messages can be printed in full. That includes string literals, mundy::StringLiteral, and literal-only sinks such as mundy::sink() << "left " << "right". Other message types still abort, but they fall back to file and line information plus a generic note.

Parameters
assertion_to_testThe assertion to test
exception_to_throwThe exception to throw if the assertion is false (will only be thrown on the host)
message_to_printThe message to print if the assertion is false

◆ MUNDY_THROW_ASSERT

#define MUNDY_THROW_ASSERT ( assertion_to_test,
exception_to_throw,
message_to_print )
Value:
MUNDY_THROW_REQUIRE(assertion_to_test, exception_to_throw, message_to_print)
#define MUNDY_THROW_REQUIRE(assertion_to_test, exception_to_throw, message_to_print)
Abort the code if the given assertion is false.
Definition throw_assert.hpp:207
Note
This macro is only compiled if NDEBUG is not defined. Well, that's a lie. Technically, we still use the assertion_to_test but only its type and not its value. This avoids unused variable warnings and shouldn't have any performance impact. TODO(palmerb4): Formally benchmark this claim. At least in prelim tests, it is true.
Parameters
assertion_to_testThe assertion to test
exception_to_throwThe exception to throw if the assertion is false (will only be thrown on the host)
message_to_printThe message to print if the assertion is false