21#include <kassert/kassert.hpp>
23#ifdef KAMPING_ENABLE_REFLECTION
24 #include <boost/pfr.hpp>
48template <
typename T1,
typename T2>
55template <
typename...
Ts>
63template <
typename T,
size_t N>
66 static constexpr size_t size =
N;
71template <
typename T,
size_t N>
97#ifdef KAMPING_ENABLE_REFLECTION
100 || boost::pfr::is_implicitly_reflectable<T, kamping_tag>::value,
101 "Type must be a std::pair, std::tuple or reflectable"
137 !std::is_pointer_v<T_no_const>,
138 "MPI does not support pointer types. Why do you want to transfer a pointer over MPI?"
141 static_assert(!std::is_function_v<T_no_const>,
"MPI does not support function types.");
144 static_assert(!std::is_union_v<T_no_const>,
"MPI does not support union types.");
146 static_assert(!std::is_void_v<T_no_const>,
"There is no MPI datatype corresponding to void.");
151 }
else if constexpr (std::is_enum_v<T_no_const>) {
154 }
else if constexpr (std::is_array_v<T_no_const>) {
156 constexpr size_t array_size = std::extent_v<T_no_const>;
164 }
else if constexpr (std::is_trivially_copyable_v<T_no_const>) {
202template <
typename T,
typename Enable =
void>
251template <
typename,
typename Enable =
void>
274 mpi_env.register_mpi_type(type);
297 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
308template <
typename T,
size_t N>
312 if constexpr (std::is_same_v<T, std::byte>) {
317 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
321 int count =
static_cast<int>(
N);
331template <
typename T,
typename F,
size_t...
Is>
333 (f(std::get<Is>(std::forward<T>(
t)),
Is), ...);
339template <
typename T,
typename F>
350template <
typename T,
typename F>
355#ifdef KAMPING_ENABLE_REFLECTION
356 boost::pfr::for_each_field(
t, std::forward<F>(f));
373 return std::tuple_size_v<T>;
375#ifdef KAMPING_ENABLE_REFLECTION
376 return boost::pfr::tuple_size_v<T>;
378 if constexpr (std::is_arithmetic_v<T>) {
381 return std::tuple_size_v<T>;
401 "\n --> Type not supported directly by KaMPIng. Please provide a specialization for mpi_type_traits."
439 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:418
ScopedDatatype(ScopedDatatype const &)=delete
Deleted copy constructor.
ScopedDatatype & operator=(ScopedDatatype &&other) noexcept
Move assignment.
Definition mpi_datatype.hpp:438
ScopedDatatype(ScopedDatatype &&other) noexcept
Move constructor.
Definition mpi_datatype.hpp:434
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:423
~ScopedDatatype()
Free the MPI_Datatype.
Definition mpi_datatype.hpp:447
MPI_Datatype const & data_type() const
Get the MPI_Datatype.
Definition mpi_datatype.hpp:443
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:131
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:261
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type.
Definition mpi_datatype.hpp:389
MPI_Datatype mpi_datatype() KAMPING_NOEXCEPT
Translate template parameter T to an MPI_Datatype. If no corresponding MPI_Datatype exists,...
Definition mpi_datatype.hpp:294
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type.
Definition mpi_datatype.hpp:309
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:270
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:332
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:351
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:369
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:83
Constructs an contiguous type of size N from type T using MPI_Type_contiguous.
Definition mpi_datatype.hpp:72
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:75
static constexpr TypeCategory category
Definition mpi_datatype.hpp:73
Check if the type has a static type definition, i.e. mpi_type_traits is defined.
Definition mpi_datatype.hpp:252
T value_type
The type of the elements in the array.
Definition mpi_datatype.hpp:65
Helper to check if a type is a std::array.
Definition mpi_datatype.hpp:60
Helper to check if a type is a std::pair.
Definition mpi_datatype.hpp:46
Helper to check if a type is a std::tuple.
Definition mpi_datatype.hpp:53
Tag used for indicating that a struct is reflectable.
Definition mpi_datatype.hpp:34
static MPI_Datatype data_type()
The MPI_Datatype corresponding to the type T.
Definition mpi_datatype.hpp:245
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:203
Type tag for indicating that no static type definition exists for a type.
Definition mpi_datatype.hpp:117
Constructs a MPI_Datatype for a struct-like type.
Definition mpi_datatype.hpp:96
static constexpr TypeCategory category
The category of the type.
Definition mpi_datatype.hpp:109
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:111