8#ifdef NF_WITH_MPI_SUPPORT
19#ifdef NF_WITH_MPI_SUPPORT
46constexpr MPI_Op getOp(
const ReduceOp op)
66 case ReduceOp::Maxloc:
68 case ReduceOp::Minloc:
82template<
typename valueType>
83constexpr MPI_Datatype getType()
85 if constexpr (std::is_same_v<valueType, char>)
return MPI_CHAR;
86 else if constexpr (std::is_same_v<valueType, wchar_t>)
88 else if constexpr (std::is_same_v<valueType, short>)
90 else if constexpr (std::is_same_v<valueType, int>)
92 else if constexpr (std::is_same_v<valueType, long>)
94 else if constexpr (std::is_same_v<valueType, long long>)
96 else if constexpr (std::is_same_v<valueType, unsigned short>)
97 return MPI_UNSIGNED_SHORT;
98 else if constexpr (std::is_same_v<valueType, unsigned>)
100 else if constexpr (std::is_same_v<valueType, unsigned long>)
101 return MPI_UNSIGNED_LONG;
102 else if constexpr (std::is_same_v<valueType, unsigned long long>)
103 return MPI_UNSIGNED_LONG_LONG;
104 else if constexpr (std::is_same_v<valueType, float>)
106 else if constexpr (std::is_same_v<valueType, double>)
108 else if constexpr (std::is_same_v<valueType, long double>)
109 return MPI_LONG_DOUBLE;
110 else if constexpr (std::is_same_v<valueType, bool>)
112 else if constexpr (std::is_same_v<valueType, std::complex<float>>)
113 return MPI_CXX_FLOAT_COMPLEX;
114 else if constexpr (std::is_same_v<valueType, std::complex<double>>)
115 return MPI_CXX_DOUBLE_COMPLEX;
116 else if constexpr (std::is_same_v<valueType, std::complex<long double>>)
117 return MPI_CXX_LONG_DOUBLE_COMPLEX;
133template<
typename valueType>
134void allReduce(valueType& value,
const ReduceOp op, MPI_Comm comm)
137 MPI_IN_PLACE,
reinterpret_cast<void*
>(&value), 1, getType<valueType>(), getOp(op), comm
151inline void allReduce(Vec3& vector,
const ReduceOp op, MPI_Comm comm)
155 reinterpret_cast<void*
>(vector.data()),
175template<
typename valueType>
177 const valueType* buffer,
178 const mpi_label_t size,
179 mpi_label_t rankReceive,
186 MPI_Isend(buffer, size, getType<valueType>(), rankReceive, tag, comm, request);
202template<
typename valueType>
205 const mpi_label_t size,
206 mpi_label_t rankSend,
212 mpi_label_t err = MPI_Irecv(buffer, size, getType<valueType>(), rankSend, tag, comm, request);
223inline bool test(MPI_Request* request)
226 mpi_label_t err = MPI_Test(request, &flag, MPI_STATUS_IGNORE);
228 return static_cast<bool>(flag);
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
#define NF_DEBUG_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false (only in debu...