BioCMAMC-ST
mpi_types.hpp
1#ifndef __MPI_TYPES_HPP__
2#define __MPI_TYPES_HPP__
3
4#include <mpi.h>
5#include <mpi_w/message_t.hpp>
6#include <type_traits>
7
8namespace WrapMPI
9{
10
11 template <typename T>
12 constexpr MPI_Datatype
13 get_type() noexcept
14 {
15 MPI_Datatype datatype{};
16
17 using _type = std::remove_const_t<std::remove_reference_t<T>>;
18
19 if constexpr (std::is_same_v<_type, size_t>)
20 {
21 datatype = MPI_UNSIGNED_LONG;
22 }
23 else if constexpr (std::is_same_v<_type, double>)
24 {
25 datatype = MPI_DOUBLE;
26 }
27 else if constexpr (std::is_same_v<_type, int>)
28 {
29 datatype = MPI_INT;
30 }
31 else if constexpr (std::is_same_v<_type, bool>)
32 {
33 datatype = MPI_CXX_BOOL;
34 }
35 else if constexpr (std::is_same_v<_type, char>
36 || std::is_same_v<_type, WrapMPI::SIGNALS>)
37 {
38 datatype = MPI_BYTE;
39 }
40 else
41 {
42 []<bool flag = false>() { static_assert(flag, "no match"); }();
43 }
44
45 return datatype;
46 }
47} // namespace WrapMPI
48
49#endif //__MPI_TYPES_HPP__
Namespace to correclty wrap MPI C API for modern C++.
Definition impl_async.hpp:14
constexpr MPI_Datatype get_type() noexcept
Definition mpi_types.hpp:13