35#ifdef PARALLEL_MODE_MPI
37MpiManager::MpiManager() : ok(false), clout(std::cout,
"MpiManager")
40MpiManager::~MpiManager()
51 MPI_Initialized(&ok0);
55 int ok1 = MPI_Init(argc, argv);
56 int ok2 = MPI_Comm_rank(MPI_COMM_WORLD, &taskId);
57 int ok3 = MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
58 int ok4 = MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
59 ok = (ok1 == MPI_SUCCESS && ok2 == MPI_SUCCESS && ok3 == MPI_SUCCESS && ok4 == MPI_SUCCESS);
61 clout <<
"Sucessfully initialized, numThreads=" <<
getSize() << std::endl;
113 MPI_Send(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm);
122 MPI_Send(
static_cast<void*
>(buf), count, MPI_CHAR, dest, tag, comm);
126void MpiManager::send<std::uint8_t>(std::uint8_t *buf,
int count,
int dest,
int tag, MPI_Comm comm)
131 MPI_Send(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm);
140 MPI_Send(
static_cast<void*
>(buf), count, MPI_INT, dest, tag, comm);
149 MPI_Send(
static_cast<void*
>(buf), count, MPI_FLOAT, dest, tag, comm);
158 MPI_Send(
static_cast<void*
>(buf), count, MPI_DOUBLE, dest, tag, comm);
165 MPI_Send_init(buf, count, MPI_DOUBLE, dest, tag, comm, request);
170void MpiManager::sendInit<std::size_t>(std::size_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
173 MPI_Send_init(buf, count, MPI_UNSIGNED_LONG, dest, tag, comm, request);
178void MpiManager::sendInit<std::uint32_t>(std::uint32_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
181 MPI_Send_init(buf, count, MPI_UNSIGNED, dest, tag, comm, request);
186void MpiManager::sendInit<std::uint8_t>(std::uint8_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
189 MPI_Send_init(buf, count, MPI_BYTE, dest, tag, comm, request);
197 MPI_Send_init(buf, count, MPI_INT, dest, tag, comm, request);
205 MPI_Send_init(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm, request);
211(
bool *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
214 MPI_Isend(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm, request);
220(
char *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
223 MPI_Isend(
static_cast<void*
>(buf), count, MPI_CHAR, dest, tag, comm, request);
228void MpiManager::iSend<std::uint8_t>
229(std::uint8_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
232 MPI_Isend(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm, request);
238(
int *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
241 MPI_Isend(
static_cast<void*
>(buf), count, MPI_INT, dest, tag, comm, request);
246void MpiManager::iSend<std::size_t>
247(std::size_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
250 MPI_Isend(
static_cast<void*
>(buf), count, MPI_UNSIGNED_LONG, dest, tag, comm, request);
255void MpiManager::iSend<std::uint32_t>
256(std::uint32_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
259 MPI_Isend(
static_cast<void*
>(buf), count, MPI_UNSIGNED, dest, tag, comm, request);
265(
float *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
268 MPI_Isend(
static_cast<void*
>(buf), count, MPI_FLOAT, dest, tag, comm, request);
274(
double *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
277 MPI_Isend(
static_cast<void*
>(buf), count, MPI_DOUBLE, dest, tag, comm, request);
283(
long double *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
286 MPI_Isend(
static_cast<void*
>(buf), count, MPI_LONG_DOUBLE, dest, tag, comm, request);
293(
bool *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
296 MPI_Ibsend(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm, request);
302(
char *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
305 MPI_Ibsend(
static_cast<void*
>(buf), count, MPI_CHAR, dest, tag, comm, request);
311(
int *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
314 MPI_Ibsend(
static_cast<void*
>(buf), count, MPI_INT, dest, tag, comm, request);
320(
float *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
323 MPI_Ibsend(
static_cast<void*
>(buf), count, MPI_FLOAT, dest, tag, comm, request);
329(
double *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
332 MPI_Ibsend(
static_cast<void*
>(buf), count, MPI_DOUBLE, dest, tag, comm, request);
339 if (MPI_Probe(source, tag, comm, &status) == MPI_SUCCESS) {
341 MPI_Get_count(&status, type, &requestSize);
342 if (requestSize == MPI_UNDEFINED) {
343 throw std::runtime_error(
"MPI_UNDEFINED in probeReceiveSize(" + std::to_string(source) +
"," + std::to_string(tag) +
")" +
" ranks " + std::to_string(source) +
" -> " + std::to_string(
singleton::mpi().
getRank()));
347 throw std::runtime_error(
"MPI_Probe failed in probeReceiveSize");
352std::size_t MpiManager::probeReceiveSize<std::uint32_t>(
int source,
int tag, MPI_Comm comm)
354 return probeReceiveSize(source, MPI_UNSIGNED, tag, comm);
358std::size_t MpiManager::probeReceiveSize<std::uint64_t>(
int source,
int tag, MPI_Comm comm)
360 return probeReceiveSize(source, MPI_UNSIGNED_LONG, tag, comm);
370 MPI_Recv(
static_cast<void*
>(buf), count, MPI_BYTE, source, tag, comm, &status);
381 MPI_Recv(
static_cast<void*
>(buf), count, MPI_CHAR, source, tag, comm, &status);
385void MpiManager::receive<std::uint8_t>(std::uint8_t *buf,
int count,
int source,
int tag, MPI_Comm comm)
391 MPI_Recv(
static_cast<std::uint8_t*
>(buf), count, MPI_BYTE, source, tag, comm, &status);
401 MPI_Recv(
static_cast<void*
>(buf), count, MPI_INT, source, tag, comm, &status);
405void MpiManager::receive<std::size_t>(std::size_t *buf,
int count,
int source,
int tag, MPI_Comm comm)
411 MPI_Recv(
static_cast<void*
>(buf), count, MPI_UNSIGNED_LONG, source, tag, comm, &status);
415void MpiManager::receive<std::uint32_t>(std::uint32_t *buf,
int count,
int source,
int tag, MPI_Comm comm)
421 MPI_Recv(
static_cast<void*
>(buf), count, MPI_UNSIGNED, source, tag, comm, &status);
431 MPI_Recv(
static_cast<void*
>(buf), count, MPI_FLOAT, source, tag, comm, &status);
441 MPI_Recv(
static_cast<void*
>(buf), count, MPI_DOUBLE, source, tag, comm, &status);
451 MPI_Recv(
static_cast<void*
>(buf), count, MPI_LONG_DOUBLE, source, tag, comm, &status);
461 send(sendBuf, sendCount, 0);
464 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
475 send(sendBuf, sendCount, 0);
478 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
489 send(sendBuf, sendCount, 0);
492 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
503 send(sendBuf, sendCount, 0);
506 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
517 send(sendBuf, sendCount, 0);
520 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
528 MPI_Recv_init(buf, count, MPI_DOUBLE, dest, tag, comm, request);
536 MPI_Recv_init(buf, count, MPI_INT, dest, tag, comm, request);
541void MpiManager::recvInit<std::uint8_t>(std::uint8_t *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
544 MPI_Recv_init(buf, count, MPI_BYTE, dest, tag, comm, request);
552 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_BYTE, source, tag, comm, request);
560 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_CHAR, source, tag, comm, request);
568 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_INT, source, tag, comm, request);
576 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_FLOAT, source, tag, comm, request);
584 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_DOUBLE, source, tag, comm, request);
590(
bool *sendBuf,
bool *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
596 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
599 static_cast<void*
>(recvBuf),
601 MPI_BYTE, source, tag, comm, &status);
606(
char *sendBuf,
char *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
612 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
615 static_cast<void*
>(recvBuf),
617 MPI_CHAR, source, tag, comm, &status);
622(
int *sendBuf,
int *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
628 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
631 static_cast<void*
>(recvBuf),
633 MPI_INT, source, tag, comm, &status);
638(
float *sendBuf,
float *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
644 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
646 MPI_FLOAT, dest, tag,
647 static_cast<void*
>(recvBuf),
649 MPI_FLOAT, source, tag, comm, &status);
654(
long *sendBuf,
long *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
660 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
663 static_cast<void*
>(recvBuf),
665 MPI_LONG, source, tag, comm, &status);
670(
double *sendBuf,
double *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
676 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
678 MPI_DOUBLE, dest, tag,
679 static_cast<void*
>(recvBuf),
681 MPI_DOUBLE, source, tag, comm, &status);
686(
long double *sendBuf,
long double *recvBuf,
int count,
int dest,
int source,
int tag, MPI_Comm comm)
692 MPI_Sendrecv(
static_cast<void*
>(sendBuf),
694 MPI_LONG_DOUBLE, dest, tag,
695 static_cast<void*
>(recvBuf),
697 MPI_LONG_DOUBLE, source, tag, comm, &status);
702 bool* recvBuf,
int recvCount,
int root, MPI_Comm comm)
707 MPI_Scatterv(
static_cast<void*
>(sendBuf),
708 sendCounts, displs, MPI_BYTE,
709 static_cast<void*
>(recvBuf),
710 recvCount, MPI_BYTE, root, comm);
715 char* recvBuf,
int recvCount,
int root, MPI_Comm comm)
720 MPI_Scatterv(
static_cast<void*
>(sendBuf),
721 sendCounts, displs, MPI_CHAR,
722 static_cast<void*
>(recvBuf),
723 recvCount, MPI_CHAR, root, comm);
728 int* recvBuf,
int recvCount,
int root, MPI_Comm comm)
733 MPI_Scatterv(
static_cast<void*
>(sendBuf),
734 sendCounts, displs, MPI_INT,
735 static_cast<void*
>(recvBuf),
736 recvCount, MPI_INT, root, comm);
741 float* recvBuf,
int recvCount,
int root, MPI_Comm comm)
746 MPI_Scatterv(
static_cast<void*
>(sendBuf),
747 sendCounts, displs, MPI_FLOAT,
748 static_cast<void*
>(recvBuf),
749 recvCount, MPI_FLOAT, root, comm);
754 double* recvBuf,
int recvCount,
int root, MPI_Comm comm)
759 MPI_Scatterv(
static_cast<void*
>(sendBuf),
760 sendCounts, displs, MPI_DOUBLE,
761 static_cast<void*
>(recvBuf),
762 recvCount, MPI_DOUBLE, root, comm);
767 int* recvBuf,
int recvCount,
768 int root, MPI_Comm comm)
773 MPI_Gather(
static_cast<void*
>(sendBuf), sendCount, MPI_INT,
774 static_cast<void*
>(recvBuf), recvCount, MPI_INT,
780 bool* recvBuf,
int recvCount,
786 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_BYTE,
787 static_cast<void*
>(recvBuf), recvCount, MPI_BYTE,
793 char* recvBuf,
int recvCount,
799 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_CHAR,
800 static_cast<void*
>(recvBuf), recvCount, MPI_CHAR,
806 int* recvBuf,
int recvCount,
812 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_INT,
813 static_cast<void*
>(recvBuf), recvCount, MPI_INT,
819 float* recvBuf,
int recvCount,
825 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_FLOAT,
826 static_cast<void*
>(recvBuf), recvCount, MPI_FLOAT,
832 double* recvBuf,
int recvCount,
838 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_DOUBLE,
839 static_cast<void*
>(recvBuf), recvCount, MPI_DOUBLE,
844void MpiManager::allGather<std::size_t>(std::size_t* sendBuf,
int sendCount,
845 std::size_t* recvBuf,
int recvCount,
851 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_UNSIGNED_LONG,
852 static_cast<void*
>(recvBuf), recvCount, MPI_UNSIGNED_LONG,
856#if defined(__x86_64__) || defined(_M_X64) || defined(__ppc64__) || defined(__aarch64__)
859 std::uint32_t* recvBuf,
int recvCount,
865 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_UINT32_T,
866 static_cast<void*
>(recvBuf), recvCount, MPI_UINT32_T,
871void MpiManager::allGather<std::uint64_t>(std::uint64_t* sendBuf,
int sendCount,
872 std::uint64_t* recvBuf,
int recvCount,
878 MPI_Allgather(
static_cast<void*
>(sendBuf), sendCount, MPI_UINT64_T,
879 static_cast<void*
>(recvBuf), recvCount, MPI_UINT64_T,
886 bool* recvBuf,
int* recvCounts,
int* displs,
887 int root, MPI_Comm comm)
892 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_BYTE,
893 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_BYTE,
899 char* recvBuf,
int* recvCounts,
int* displs,
900 int root, MPI_Comm comm)
905 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_CHAR,
906 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_CHAR,
912 int* recvBuf,
int* recvCounts,
int* displs,
913 int root, MPI_Comm comm)
918 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_INT,
919 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_INT,
925 float* recvBuf,
int* recvCounts,
int* displs,
926 int root, MPI_Comm comm)
931 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_FLOAT,
932 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_FLOAT,
938 double* recvBuf,
int* recvCounts,
int* displs,
939 int root, MPI_Comm comm)
944 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_DOUBLE,
945 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_DOUBLE,
950void MpiManager::gatherv<std::size_t>(std::size_t* sendBuf,
int sendCount,
951 std::size_t* recvBuf,
int* recvCounts,
int* displs,
952 int root, MPI_Comm comm)
957 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_UNSIGNED_LONG,
958 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_UNSIGNED_LONG,
964 bool* recvBuf,
int* recvCounts,
int* displs,
970 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_BYTE,
971 static_cast<void*
>(recvBuf), recvCounts, displs,
977 char* recvBuf,
int* recvCounts,
int* displs,
983 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_CHAR,
984 static_cast<void*
>(recvBuf), recvCounts, displs,
990 int* recvBuf,
int* recvCounts,
int* displs,
996 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_INT,
997 static_cast<void*
>(recvBuf), recvCounts, displs,
1003 float* recvBuf,
int* recvCounts,
int* displs,
1009 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_FLOAT,
1010 static_cast<void*
>(recvBuf), recvCounts, displs,
1016 double* recvBuf,
int* recvCounts,
int* displs,
1022 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_DOUBLE,
1023 static_cast<void*
>(recvBuf), recvCounts, displs,
1028void MpiManager::allGatherv<std::size_t>(std::size_t* sendBuf,
int sendCount,
1029 std::size_t* recvBuf,
int* recvCounts,
int* displs,
1035 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_UNSIGNED_LONG,
1036 static_cast<void*
>(recvBuf), recvCounts, displs,
1037 MPI_UNSIGNED_LONG, comm);
1040#if defined(__x86_64__) || defined(_M_X64) || defined(__ppc64__) || defined(__aarch64__)
1043 std::uint32_t* recvBuf,
int* recvCounts,
int* displs,
1049 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_UINT32_T,
1050 static_cast<void*
>(recvBuf), recvCounts, displs,
1051 MPI_UINT32_T, comm);
1055void MpiManager::allGatherv<std::uint64_t>(std::uint64_t* sendBuf,
int sendCount,
1056 std::uint64_t* recvBuf,
int* recvCounts,
int* displs,
1062 MPI_Allgatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_UINT64_T,
1063 static_cast<void*
>(recvBuf), recvCounts, displs,
1064 MPI_UINT64_T, comm);
1074 MPI_Bcast(
static_cast<void*
>(sendBuf),
1075 sendCount, MPI_BYTE, root, comm);
1084 MPI_Bcast(
static_cast<void*
>(sendBuf),
1085 sendCount, MPI_CHAR, root, comm);
1094 MPI_Bcast(
static_cast<void*
>(sendBuf),
1095 sendCount, MPI_UNSIGNED_CHAR, root, comm);
1104 MPI_Bcast(
static_cast<void*
>(sendBuf),
1105 sendCount, MPI_INT, root, comm);
1114 MPI_Bcast(
static_cast<void*
>(sendBuf),
1115 sendCount, MPI_UNSIGNED_LONG, root, comm);
1124 MPI_Bcast(
static_cast<void*
>(sendBuf),
1125 sendCount, MPI_FLOAT, root, comm);
1134 MPI_Bcast(
static_cast<void*
>(sendBuf),
1135 sendCount, MPI_DOUBLE, root, comm);
1140void MpiManager::bCast<std::string>(std::string* sendBuf,
int sendCount,
int root, MPI_Comm comm)
1145 int length = (int) sendBuf->size();
1146 MPI_Bcast(
static_cast<void*
>(&length), 1, MPI_INT, root, comm);
1147 char* buffer =
new char[length+1];
1148 if (getRank()==root) {
1149 std::copy(sendBuf->c_str(), sendBuf->c_str()+length+1, buffer);
1151 MPI_Bcast(
static_cast<void*
>(buffer), length+1, MPI_CHAR, root, comm);
1152 if (getRank()!=root) {
1164 MPI_Bcast(&sendVal, 1, MPI_BYTE, root, comm);
1172 MPI_Bcast(&sendVal, 1, MPI_CHAR, root, comm);
1181 MPI_Bcast(&sendVal, 1, MPI_UNSIGNED_CHAR, root, comm);
1190 MPI_Bcast(&sendVal, 1, MPI_INT, root, comm);
1199 MPI_Bcast(&sendVal, 1, MPI_UNSIGNED_LONG, root, comm);
1208 MPI_Bcast(&sendVal, 1, MPI_FLOAT, root, comm);
1217 MPI_Bcast(&sendVal, 1, MPI_DOUBLE, root, comm);
1227 send(sendBuf, sendCount, 0);
1230 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1232 bCast(sendBuf, sendCount, 0);
1242 send(sendBuf, sendCount, 0);
1245 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1247 bCast(sendBuf, sendCount, 0);
1257 send(sendBuf, sendCount, 0);
1260 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1262 bCast(sendBuf, sendCount, 0);
1272 send(sendBuf, sendCount, 0);
1275 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1277 bCast(sendBuf, sendCount, 0);
1287 send(sendBuf, sendCount, 0);
1290 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1292 bCast(sendBuf, sendCount, 0);
1301 MPI_Reduce(
static_cast<void*
>(&sendVal),
1302 static_cast<void*
>(&recvVal), 1, MPI_BYTE, op, root, comm);
1311 MPI_Reduce(
static_cast<void*
>(&sendVal),
1312 static_cast<void*
>(&recvVal), 1, MPI_CHAR, op, root, comm);
1321 MPI_Reduce(
static_cast<void*
>(&sendVal),
1322 static_cast<void*
>(&recvVal), 1, MPI_INT, op, root, comm);
1331 MPI_Reduce(
static_cast<void*
>(&sendVal),
1332 static_cast<void*
>(&recvVal), 1, MPI_FLOAT, op, root, comm);
1341 MPI_Reduce(sendVal, recvVal, count, MPI_FLOAT, op, root, comm);
1350 MPI_Reduce(
static_cast<void*
>(&sendVal),
1351 static_cast<void*
>(&recvVal), 1, MPI_DOUBLE, op, root, comm);
1355void MpiManager::reduce<std::size_t>(std::size_t& sendVal, std::size_t& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1360 MPI_Reduce(
static_cast<void*
>(&sendVal),
1361 static_cast<void*
>(&recvVal), 1, MPI_UNSIGNED_LONG, op, root, comm);
1366 MPI_Op op,
int root, MPI_Comm comm)
1371 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1372 static_cast<void*
>(&(recvVal[0])),
1373 sendVal.size(), MPI_CHAR, op, root, comm);
1378 MPI_Op op,
int root, MPI_Comm comm)
1383 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1384 static_cast<void*
>(&(recvVal[0])),
1385 sendVal.size(), MPI_INT, op, root, comm);
1390 MPI_Op op,
int root, MPI_Comm comm)
1395 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1396 static_cast<void*
>(&(recvVal[0])),
1397 sendVal.size(), MPI_FLOAT, op, root, comm);
1402 MPI_Op op,
int root, MPI_Comm comm)
1407 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1408 static_cast<void*
>(&(recvVal[0])),
1409 sendVal.size(), MPI_DOUBLE, op, root, comm);
1419 MPI_Reduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_BYTE, op, root, comm);
1420 reductVal = recvVal;
1421 MPI_Bcast(&reductVal, 1, MPI_BYTE, root, comm);
1432 MPI_Reduce(&reductVal, &recvVal, 1, MPI_CHAR, op, root, comm);
1433 reductVal = recvVal;
1434 MPI_Bcast(&reductVal, 1, MPI_CHAR, root, comm);
1445 MPI_Reduce(&reductVal, &recvVal, 1, MPI_INT, op, root, comm);
1446 reductVal = recvVal;
1447 MPI_Bcast(&reductVal, 1, MPI_INT, root, comm);
1458 MPI_Reduce(&reductVal, &recvVal, 1, MPI_FLOAT, op, root, comm);
1459 reductVal = recvVal;
1460 MPI_Bcast(&reductVal, 1, MPI_FLOAT, root, comm);
1470 MPI_Reduce(&reductVal, &recvVal, 1, MPI_DOUBLE, op, root, comm);
1471 reductVal = recvVal;
1472 MPI_Bcast(&reductVal, 1, MPI_DOUBLE, root, comm);
1482 long double recvVal;
1483 MPI_Reduce(&reductVal, &recvVal, 1, MPI_LONG_DOUBLE, op, root, comm);
1484 reductVal = recvVal;
1485 MPI_Bcast(&reductVal, 1, MPI_LONG_DOUBLE, root, comm);
1496 MPI_Reduce(&reductVal, &recvVal, 1, MPI_LONG, op, root, comm);
1497 reductVal = recvVal;
1498 MPI_Bcast(&reductVal, 1, MPI_LONG, root, comm);
1508 unsigned long recvVal;
1509 MPI_Reduce(&reductVal, &recvVal, 1, MPI_UNSIGNED_LONG, op, root, comm);
1510 reductVal = recvVal;
1511 MPI_Bcast(&reductVal, 1, MPI_UNSIGNED_LONG, root, comm);
1521 MPI_Allreduce(in, out, count, MPI_FLOAT, op, comm);
1530 MPI_Allreduce(in, out, count, MPI_DOUBLE, op, comm);
1539 MPI_Allreduce(in, out, count, MPI_UNSIGNED, op, comm);
1548 MPI_Allreduce(in, out, count, MPI_INT, op, comm);
1558 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_BYTE, op, comm);
1559 reductVal = recvVal;
1569 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_CHAR, op, comm);
1570 reductVal = recvVal;
1580 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_INT, op, comm);
1581 reductVal = recvVal;
1591 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_FLOAT, op, comm);
1592 reductVal = recvVal;
1602 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_DOUBLE, op, comm);
1603 reductVal = recvVal;
1612 long double recvVal;
1613 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_LONG_DOUBLE, op, comm);
1614 reductVal = recvVal;
1618void MpiManager::allReduce<std::size_t>(std::size_t& reductVal, MPI_Op op, MPI_Comm comm)
1623 std::size_t recvVal;
1624 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_UNSIGNED_LONG, op, comm);
1625 reductVal = recvVal;
1628#if defined(__x86_64__) || defined(_M_X64) || defined(__ppc64__) || defined(__aarch64__)
1635 std::uint32_t recvVal;
1636 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_UNSIGNED, op, comm);
1637 reductVal = recvVal;
1641void MpiManager::allReduce<std::uint64_t>(std::uint64_t& reductVal, MPI_Op op, MPI_Comm comm)
1646 std::uint64_t recvVal;
1647 MPI_Allreduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_UNSIGNED_LONG, op, comm);
1648 reductVal = recvVal;
1658 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_CHAR, op, comm);
1667 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_INT, op, comm);
1676 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_FLOAT, op, comm);
1685 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_DOUBLE, op, comm);
1694 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_LONG_DOUBLE, op, comm);
1698void MpiManager::allReduceVect<std::size_t>(std::vector<std::size_t>& reductVal, MPI_Op op, MPI_Comm comm)
1703 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_UNSIGNED_LONG, op, comm);
1706#if defined(__x86_64__) || defined(_M_X64) || defined(__ppc64__) || defined(__aarch64__)
1713 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_UNSIGNED, op, comm);
1717void MpiManager::allReduceVect<std::uint64_t>(std::vector<std::uint64_t>& reductVal, MPI_Op op, MPI_Comm comm)
1722 MPI_Allreduce(MPI_IN_PLACE,
static_cast<void*
>(reductVal.data()),
static_cast<int>(reductVal.size()), MPI_UNSIGNED_LONG, op, comm);
1731 MPI_Wait(request, status);
1736 if (!ok || mpiNbHelper.
get_size() == 0) {
1749 std::swap(_size, rhs._size);
1750 std::swap(_mpiRequest, rhs._mpiRequest);
1751 std::swap(_mpiStatus, rhs._mpiStatus);
1757 _mpiRequest.reset(
new MPI_Request[n] { });
1758 _mpiStatus.reset(
new MPI_Status[n] { });
1775 return &_mpiRequest[i];
1781 return &_mpiStatus[i];
Wrapper functions that simplify the use of MPI.
void gather(T *sendBuf, int sendCount, T *recvBuf, int recvCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Gather data from multiple processors to one processor.
void wait(MPI_Request *request, MPI_Status *status)
Complete a non-blocking MPI operation.
void send(T *buf, int count, int dest, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Sends data at *buf, blocking.
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
int getSize() const
Returns the number of processes.
void iSend(T *buf, int count, int dest, MPI_Request *request, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Sends data at *buf, non blocking.
void allreduce(const T *in, T *out, int count, MPI_Op op, MPI_Comm comm=MPI_COMM_WORLD)
void reduce(T &sendVal, T &recvVal, MPI_Op op, int root=0, MPI_Comm=MPI_COMM_WORLD)
Reduction operation toward one processor.
double getTime() const
Returns universal MPI-time in seconds.
bool isMainProcessor() const
Tells whether current processor is main processor.
void gatherv(T *sendBuf, int sendCount, T *recvBuf, int *recvCounts, int *displs, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Gather data from multiple processors to one processor.
void synchronizeIO(unsigned tDelay=100, MPI_Comm comm=MPI_COMM_WORLD)
Synchronizes the processes and wait to ensure correct cout order.
void reduceVect(std::vector< T > &sendVal, std::vector< T > &recvVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Element-per-element reduction of a vector of data.
void ibSend(T *buf, int count, int dest, MPI_Request *request, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Sends data at *buf, non blocking and buffered.
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
int getRank() const
Returns the process ID.
std::size_t probeReceiveSize(int source, MPI_Datatype type, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Probe size of incoming message.
void allReduceVect(std::vector< T > &reductVal, MPI_Op op, MPI_Comm comm=MPI_COMM_WORLD)
Element-per-element all-reduction of a vector of data (in-place)
void allGatherv(T *sendBuf, int sendCount, T *recvBuf, int *recvCounts, int *displs, MPI_Comm comm=MPI_COMM_WORLD)
Gather data from multiple processors to every processor.
void waitAll(MpiNonBlockingHelper &mpiNbHelper)
Complete a series of non-blocking MPI operations.
void barrier(MPI_Comm comm=MPI_COMM_WORLD)
Synchronizes the processes.
void bCastThroughMaster(T *sendBuf, int sendCount, bool iAmRoot, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data when root is unknown to other processors.
void allGather(T *sendBuf, int sendCount, T *recvBuf, int recvCount, MPI_Comm comm=MPI_COMM_WORLD)
Gather data from multiple processors to every processor.
void iRecv(T *buf, int count, int source, MPI_Request *request, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Receives data at *buf, non blocking.
void init(int *argc, char ***argv, bool verbose=true)
Initializes the mpi manager.
void recvInit(T *buf, int count, int dest, MPI_Request *request, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Initialize persistent non-blocking receive.
void scatterv(T *sendBuf, int *sendCounts, int *displs, T *recvBuf, int recvCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Scatter data from one processor over multiple processors.
void allReduce(T &reductVal, MPI_Op op, MPI_Comm comm=MPI_COMM_WORLD)
All reduction operation of a vector data.
void sendInit(T *buf, int count, int dest, MPI_Request *request, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Initialize persistent non-blocking send.
int bossId() const
Returns process ID of main processor.
void sendToMaster(T *sendBuf, int sendCount, bool iAmRoot, MPI_Comm comm=MPI_COMM_WORLD)
Sends data to master processor.
void sendRecv(T *sendBuf, T *recvBuf, int count, int dest, int source, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Send and receive data between two partners.
void receive(T *buf, int count, int source, int tag=0, MPI_Comm comm=MPI_COMM_WORLD)
Receives data at *buf, blocking.
Helper class for non blocking MPI communication.
void allocate(unsigned i)
Allocates memory.
MPI_Status * get_mpiStatus(int i=0) const
Get the specified status object.
MPI_Request * get_mpiRequest(int i=0) const
Get the specified request object.
void swap(MpiNonBlockingHelper &rhs)
Swap method.
unsigned get_size() const
Returns the size of the vector _mpiRequest/_mpiStatus.
Wrapper functions that simplify the use of MPI.
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)