SOPT
Sparse OPTimisation
registered_types.h
Go to the documentation of this file.
1 #ifndef SOPT_MPI_TYPES_H
2 #define SOPT_MPI_TYPES_H
3 
4 #include "sopt/config.h"
5 #ifdef SOPT_MPI
6 #include <complex>
7 #include <mpi.h>
8 namespace sopt::mpi {
10 using MPIType = decltype(MPI_CHAR);
11 // Some MPI libraries don't actually have a type defined that will work in the above line
12 // so the line below can be used instead
13 // using MPIType = int;
14 
16 template <typename T>
17 struct Type;
18 
19 static_assert(not std::is_same<char, std::int8_t>::value, "");
20 #define SOPT_MACRO(TYPE) \
21  template <> \
22  struct Type<TYPE> { \
23  static const MPIType value; \
24  };
25 SOPT_MACRO(std::int8_t);
26 SOPT_MACRO(std::int16_t);
27 SOPT_MACRO(std::int32_t);
28 SOPT_MACRO(std::int64_t);
29 SOPT_MACRO(std::uint8_t);
30 SOPT_MACRO(std::uint16_t);
31 SOPT_MACRO(std::uint32_t);
32 SOPT_MACRO(std::uint64_t);
33 
34 #ifndef SOPT_CHAR_ARCH
35 SOPT_MACRO(char);
36 #endif
37 #ifndef SOPT_LONG_ARCH
38 SOPT_MACRO(signed long);
39 #endif
40 #ifndef SOPT_ULONG_ARCH
41 SOPT_MACRO(unsigned long);
42 #endif
43 
44 SOPT_MACRO(float);
45 SOPT_MACRO(double);
46 SOPT_MACRO(long double);
47 SOPT_MACRO(std::complex<float>);
48 SOPT_MACRO(std::complex<double>);
49 SOPT_MACRO(std::complex<long double>);
50 #undef SOPT_MACRO
51 
53 template <typename T>
54 inline constexpr MPIType registered_type(T const &) {
55  return Type<T>::value;
56 }
57 
58 namespace details {
59 template <typename... Ts>
60 struct make_void {
61  using type = void;
62 };
67 template <typename... Ts>
68 using void_t = typename make_void<Ts...>::type;
69 } // namespace details
71 template <typename T, typename = details::void_t<>>
72 class is_registered_type : public std::false_type {};
73 template <typename T>
74 class is_registered_type<T, details::void_t<decltype(Type<T>::value)>> : public std::true_type {};
75 } // namespace sopt::mpi
76 #endif
77 #endif /* ifndef SOPT_TYPES */
#define SOPT_MACRO(NAME, TYPE)