8#ifdef NF_WITH_MPI_SUPPORT
20#ifdef NF_WITH_MPI_SUPPORT
47constexpr MPI_Op getOp(
const ReduceOp op)
67 case ReduceOp::Maxloc:
69 case ReduceOp::Minloc:
83template<
typename valueType>
84constexpr MPI_Datatype getType()
86 if constexpr (std::is_same_v<valueType, char>)
return MPI_CHAR;
87 else if constexpr (std::is_same_v<valueType, wchar_t>)
89 else if constexpr (std::is_same_v<valueType, short>)
91 else if constexpr (std::is_same_v<valueType, int>)
93 else if constexpr (std::is_same_v<valueType, long>)
95 else if constexpr (std::is_same_v<valueType, long long>)
97 else if constexpr (std::is_same_v<valueType, unsigned short>)
98 return MPI_UNSIGNED_SHORT;
99 else if constexpr (std::is_same_v<valueType, unsigned>)
101 else if constexpr (std::is_same_v<valueType, unsigned long>)
102 return MPI_UNSIGNED_LONG;
103 else if constexpr (std::is_same_v<valueType, unsigned long long>)
104 return MPI_UNSIGNED_LONG_LONG;
105 else if constexpr (std::is_same_v<valueType, float>)
107 else if constexpr (std::is_same_v<valueType, double>)
109 else if constexpr (std::is_same_v<valueType, long double>)
110 return MPI_LONG_DOUBLE;
111 else if constexpr (std::is_same_v<valueType, bool>)
113 else if constexpr (std::is_same_v<valueType, std::complex<float>>)
114 return MPI_CXX_FLOAT_COMPLEX;
115 else if constexpr (std::is_same_v<valueType, std::complex<double>>)
116 return MPI_CXX_DOUBLE_COMPLEX;
117 else if constexpr (std::is_same_v<valueType, std::complex<long double>>)
118 return MPI_CXX_LONG_DOUBLE_COMPLEX;
134template<
typename valueType>
135void allReduce(valueType& value,
const ReduceOp op, MPI_Comm comm)
138 MPI_IN_PLACE,
reinterpret_cast<void*
>(&value), 1, getType<valueType>(), getOp(op), comm
152inline void allReduce(Vec3& vector,
const ReduceOp op, MPI_Comm comm)
156 reinterpret_cast<void*
>(vector.data()),
176template<
typename valueType>
178 const valueType* buffer,
179 const mpi_label_t size,
180 mpi_label_t rankReceive,
187 MPI_Isend(buffer, size, getType<valueType>(), rankReceive, tag, comm, request);
203template<
typename valueType>
206 const mpi_label_t size,
207 mpi_label_t rankSend,
213 mpi_label_t err = MPI_Irecv(buffer, size, getType<valueType>(), rankSend, tag, comm, request);
224inline bool test(MPI_Request* request)
227 mpi_label_t err = MPI_Test(request, &flag, MPI_STATUS_IGNORE);
229 return static_cast<bool>(flag);
239inline void waitAll(MPI_Request* requests,
const mpi_label_t count)
241 if (count == 0)
return;
242 mpi_label_t err = MPI_Waitall(count, requests, MPI_STATUSES_IGNORE);
252inline void waitAll(std::vector<MPI_Request>& requests)
254 waitAll(requests.data(),
static_cast<mpi_label_t>(requests.size()));
268template<
typename valueType>
270 const valueType* sendBuf,
271 mpi_label_t sendCount,
273 mpi_label_t recvCount,
278 sendBuf, sendCount, getType<valueType>(), recvBuf, recvCount, getType<valueType>(), comm
296template<
typename valueType>
298 const valueType* sendBuf,
299 const mpi_label_t* sendCounts,
300 const mpi_label_t* sendDispls,
302 const mpi_label_t* recvCounts,
303 const mpi_label_t* recvDispls,
311 getType<valueType>(),
315 getType<valueType>(),
#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...
Integer types used throughout NeoN.