23#include "kamping/kassert/kassert.hpp"
24#ifdef KAMPING_ENABLE_REFLECTION
25 #include <boost/pfr.hpp>
49template <
typename T1,
typename T2>
56template <
typename...
Ts>
64template <
typename T,
size_t N>
67 static constexpr size_t size =
N;
72template <
typename T,
size_t N>
98#ifdef KAMPING_ENABLE_REFLECTION
101 || boost::pfr::is_implicitly_reflectable<T, kamping_tag>::value,
102 "Type must be a std::pair, std::tuple or reflectable"
138 !std::is_pointer_v<T_no_const>,
139 "MPI does not support pointer types. Why do you want to transfer a pointer over MPI?"
142 static_assert(!std::is_function_v<T_no_const>,
"MPI does not support function types.");
145 static_assert(!std::is_union_v<T_no_const>,
"MPI does not support union types.");
147 static_assert(!std::is_void_v<T_no_const>,
"There is no MPI datatype corresponding to void.");
152 }
else if constexpr (std::is_enum_v<T_no_const>) {
155 }
else if constexpr (std::is_array_v<T_no_const>) {
157 constexpr size_t array_size = std::extent_v<T_no_const>;
165 }
else if constexpr (std::is_trivially_copyable_v<T_no_const>) {
203template <
typename T,
typename Enable =
void>
252template <
typename,
typename Enable =
void>
275 mpi_env.register_mpi_type(type);
298 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
309template <
typename T,
size_t N>
313 if constexpr (std::is_same_v<T, std::byte>) {
318 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
322 int count =
static_cast<int>(
N);
332template <
typename T,
typename F,
size_t...
Is>
334 (f(std::get<Is>(std::forward<T>(
t)),
Is), ...);
340template <
typename T,
typename F>
351template <
typename T,
typename F>
356#ifdef KAMPING_ENABLE_REFLECTION
357 boost::pfr::for_each_field(
t, std::forward<F>(f));
374 return std::tuple_size_v<T>;
376#ifdef KAMPING_ENABLE_REFLECTION
377 return boost::pfr::tuple_size_v<T>;
379 if constexpr (std::is_arithmetic_v<T>) {
382 return std::tuple_size_v<T>;
402 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
440 std::swap(_type,
other._type);
Mapping of C++ datatypes to builtin MPI types.
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
A scoped MPI_Datatype that commits the type on construction and frees it on destruction....
Definition mpi_datatype.hpp:419
ScopedDatatype(ScopedDatatype const &)=delete
Deleted copy constructor.
ScopedDatatype & operator=(ScopedDatatype &&other) noexcept
Move assignment.
Definition mpi_datatype.hpp:439
ScopedDatatype(ScopedDatatype &&other) noexcept
Move constructor.
Definition mpi_datatype.hpp:435
ScopedDatatype & operator=(ScopedDatatype const &)=delete
Deleted copy assignment.
ScopedDatatype(MPI_Datatype type=MPI_DATATYPE_NULL)
Construct a new scoped MPI_Datatype and commits it. If no type is provided, default to MPI_DATATYPE_N...
Definition mpi_datatype.hpp:424
~ScopedDatatype()
Free the MPI_Datatype.
Definition mpi_datatype.hpp:448
MPI_Datatype const & data_type() const
Get the MPI_Datatype.
Definition mpi_datatype.hpp:444
Wrapper for MPI functions that don't require a communicator.
Environment< InitMPIMode::NoInitFinalize > const mpi_env
A global environment object to use when you don't want to create a new Environment object.
Definition environment.hpp:323
#define THROW_IF_MPI_ERROR(error_code, function)
Wrapper around THROWING_KAMPING_ASSERT for MPI errors.
Definition error_handling.hpp:34
auto type_dispatcher()
The type dispatcher that maps a C++ type T to a type trait that can be used to construct an MPI_Datat...
Definition mpi_datatype.hpp:132
static constexpr bool has_static_type_v
Check if the type has a static type definition, i.e. has a corresponding MPI_Datatype defined followi...
Definition mpi_datatype.hpp:262
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type.
Definition mpi_datatype.hpp:390
MPI_Datatype mpi_datatype() KAMPING_NOEXCEPT
Translate template parameter T to an MPI_Datatype. If no corresponding MPI_Datatype exists,...
Definition mpi_datatype.hpp:295
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type.
Definition mpi_datatype.hpp:310
constexpr bool category_has_to_be_committed(TypeCategory category)
Checks if a type of the given category has to commited before usage in MPI calls.
Definition builtin_types.hpp:35
TypeCategory
the members specify which group the datatype belongs to according to the type groups specified in Sec...
Definition builtin_types.hpp:32
MPI_Datatype construct_and_commit_type()
Register a new MPI_Datatype for T with the MPI environment. It will be freed when the environment is ...
Definition mpi_datatype.hpp:271
void for_each_tuple_field(T &&t, F &&f, std::index_sequence< Is... >)
Applies functor f to each field of the tuple with an index in index sequence Is.
Definition mpi_datatype.hpp:333
void for_each_field(T &t, F &&f)
Applies functor f to each field of the tuple-like type t. This works for std::pair and std::tuple....
Definition mpi_datatype.hpp:352
constexpr size_t tuple_size
The number of elements in a tuple-like type. This works for std::pair and std::tuple....
Definition mpi_datatype.hpp:370
Defines the macro KAMPING_NOEXCEPT to be used instad of noexcept.
#define KAMPING_NOEXCEPT
noexcept macro.
Definition noexcept.hpp:19
Constructs a type that is serialized as a sequence of sizeof(T) bytes using MPI_BYTE....
Definition mpi_datatype.hpp:84
Constructs an contiguous type of size N from type T using MPI_Type_contiguous.
Definition mpi_datatype.hpp:73
static constexpr bool has_to_be_committed
Whether the type has to be committed before it can be used in MPI calls.
Definition mpi_datatype.hpp:76
static constexpr TypeCategory category
Definition mpi_datatype.hpp:74
Check if the type has a static type definition, i.e. mpi_type_traits is defined.
Definition mpi_datatype.hpp:253
T value_type
The type of the elements in the array.
Definition mpi_datatype.hpp:66
Helper to check if a type is a std::array.
Definition mpi_datatype.hpp:61
Helper to check if a type is a std::pair.
Definition mpi_datatype.hpp:47
Helper to check if a type is a std::tuple.
Definition mpi_datatype.hpp:54
Tag used for indicating that a struct is reflectable.
Definition mpi_datatype.hpp:35
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type T.
Definition mpi_datatype.hpp:246
The type trait that maps a C++ type T to a type trait that can be used to construct an MPI_Datatype.
Definition mpi_datatype.hpp:204
Type tag for indicating that no static type definition exists for a type.
Definition mpi_datatype.hpp:118
Constructs a MPI_Datatype for a struct-like type.
Definition mpi_datatype.hpp:97
static constexpr TypeCategory category
The category of the type.
Definition mpi_datatype.hpp:110
static constexpr bool has_to_be_committed
Whether the type has to be committed before it can be used in MPI calls.
Definition mpi_datatype.hpp:112