21#include <kassert/kassert.hpp>
46template <
typename T1,
typename T2>
53template <
typename...
Ts>
61template <
typename T,
size_t N>
64 static constexpr size_t size =
N;
69template <
typename T,
size_t N>
95 || pfr::is_implicitly_reflectable<T, kamping_tag>::value,
96 "Type must be a std::pair, std::tuple or reflectable"
127 !std::is_pointer_v<T_no_const>,
128 "MPI does not support pointer types. Why do you want to transfer a pointer over MPI?"
131 static_assert(!std::is_function_v<T_no_const>,
"MPI does not support function types.");
134 static_assert(!std::is_union_v<T_no_const>,
"MPI does not support union types.");
136 static_assert(!std::is_void_v<T_no_const>,
"There is no MPI datatype corresponding to void.");
141 }
else if constexpr (std::is_enum_v<T_no_const>) {
144 }
else if constexpr (std::is_array_v<T_no_const>) {
146 constexpr size_t array_size = std::extent_v<T_no_const>;
154 }
else if constexpr (std::is_trivially_copyable_v<T_no_const>) {
192template <
typename T,
typename Enable =
void>
241template <
typename,
typename Enable =
void>
264 mpi_env.register_mpi_type(type);
287 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
298template <
typename T,
size_t N>
302 if constexpr (std::is_same_v<T, std::byte>) {
307 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
311 int count =
static_cast<int>(
N);
321template <
typename T,
typename F,
size_t...
Is>
323 (f(std::get<Is>(std::forward<T>(
t)),
Is), ...);
329template <
typename T,
typename F>
340template <
typename T,
typename F>
345 pfr::for_each_field(
t, std::forward<F>(f));
357 return std::tuple_size_v<T>;
359 return pfr::tuple_size_v<T>;
377 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
415 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:394
ScopedDatatype(ScopedDatatype const &)=delete
Deleted copy constructor.
ScopedDatatype & operator=(ScopedDatatype &&other) noexcept
Move assignment.
Definition mpi_datatype.hpp:414
ScopedDatatype(ScopedDatatype &&other) noexcept
Move constructor.
Definition mpi_datatype.hpp:410
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:399
~ScopedDatatype()
Free the MPI_Datatype.
Definition mpi_datatype.hpp:423
MPI_Datatype const & data_type() const
Get the MPI_Datatype.
Definition mpi_datatype.hpp:419
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_KASSERT for MPI errors.
Definition error_handling.hpp:33
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:121
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:251
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type.
Definition mpi_datatype.hpp:365
MPI_Datatype mpi_datatype() KAMPING_NOEXCEPT
Translate template parameter T to an MPI_Datatype. If no corresponding MPI_Datatype exists,...
Definition mpi_datatype.hpp:284
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type.
Definition mpi_datatype.hpp:299
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:260
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:322
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 as ...
Definition mpi_datatype.hpp:341
constexpr size_t tuple_size
The number of elements in a tuple-like type. This works for std::pair and std::tuple as well as types...
Definition mpi_datatype.hpp:353
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:81
Constructs an contiguous type of size N from type T using MPI_Type_contiguous.
Definition mpi_datatype.hpp:70
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:73
static constexpr TypeCategory category
Definition mpi_datatype.hpp:71
Check if the type has a static type definition, i.e. mpi_type_traits is defined.
Definition mpi_datatype.hpp:242
T value_type
The type of the elements in the array.
Definition mpi_datatype.hpp:63
Helper to check if a type is a std::array.
Definition mpi_datatype.hpp:58
Helper to check if a type is a std::pair.
Definition mpi_datatype.hpp:44
Helper to check if a type is a std::tuple.
Definition mpi_datatype.hpp:51
Tag used for indicating that a struct is reflectable.
Definition mpi_datatype.hpp:32
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type T.
Definition mpi_datatype.hpp:235
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:193
Type tag for indicating that no static type definition exists for a type.
Definition mpi_datatype.hpp:107
Constructs a MPI_Datatype for a struct-like type.
Definition mpi_datatype.hpp:92
static constexpr TypeCategory category
The category of the type.
Definition mpi_datatype.hpp:99
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:101