6#ifdef NF_WITH_MPI_SUPPORT
17#ifdef NF_WITH_MPI_SUPPORT
44constexpr MPI_Op getOp(
const ReduceOp op)
64 case ReduceOp::Maxloc:
66 case ReduceOp::Minloc:
80template<
typename valueType>
81constexpr MPI_Datatype getType()
83 if constexpr (std::is_same_v<valueType, char>)
return MPI_CHAR;
84 else if constexpr (std::is_same_v<valueType, wchar_t>)
86 else if constexpr (std::is_same_v<valueType, short>)
88 else if constexpr (std::is_same_v<valueType, int>)
90 else if constexpr (std::is_same_v<valueType, long>)
92 else if constexpr (std::is_same_v<valueType, long long>)
94 else if constexpr (std::is_same_v<valueType, unsigned short>)
95 return MPI_UNSIGNED_SHORT;
96 else if constexpr (std::is_same_v<valueType, unsigned>)
98 else if constexpr (std::is_same_v<valueType, unsigned long>)
99 return MPI_UNSIGNED_LONG;
100 else if constexpr (std::is_same_v<valueType, unsigned long long>)
101 return MPI_UNSIGNED_LONG_LONG;
102 else if constexpr (std::is_same_v<valueType, float>)
104 else if constexpr (std::is_same_v<valueType, double>)
106 else if constexpr (std::is_same_v<valueType, long double>)
107 return MPI_LONG_DOUBLE;
108 else if constexpr (std::is_same_v<valueType, bool>)
110 else if constexpr (std::is_same_v<valueType, std::complex<float>>)
111 return MPI_CXX_FLOAT_COMPLEX;
112 else if constexpr (std::is_same_v<valueType, std::complex<double>>)
113 return MPI_CXX_DOUBLE_COMPLEX;
114 else if constexpr (std::is_same_v<valueType, std::complex<long double>>)
115 return MPI_CXX_LONG_DOUBLE_COMPLEX;
131template<
typename valueType>
132void allReduce(valueType& value,
const ReduceOp op, MPI_Comm comm)
135 MPI_IN_PLACE,
reinterpret_cast<void*
>(&value), 1, getType<valueType>(), getOp(op), comm
149inline void allReduce(Vector& vector,
const ReduceOp op, MPI_Comm comm)
153 reinterpret_cast<void*
>(vector.data()),
173template<
typename valueType>
175 const valueType* buffer,
176 const mpi_label_t size,
177 mpi_label_t rankReceive,
184 MPI_Isend(buffer, size, getType<valueType>(), rankReceive, tag, comm, request);
200template<
typename valueType>
203 const mpi_label_t size,
204 mpi_label_t rankSend,
210 mpi_label_t err = MPI_Irecv(buffer, size, getType<valueType>(), rankSend, tag, comm, request);
221inline bool test(MPI_Request* request)
224 mpi_label_t err = MPI_Test(request, &flag, MPI_STATUS_IGNORE);
226 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...