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;
108void MpiManager::send<bool>(
bool *buf,
int count,
int dest,
int tag, MPI_Comm comm)
113 MPI_Send(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm);
117void MpiManager::send<char>(
char *buf,
int count,
int dest,
int tag, MPI_Comm 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);
135void MpiManager::send<int>(
int *buf,
int count,
int dest,
int tag, MPI_Comm comm)
140 MPI_Send(
static_cast<void*
>(buf), count, MPI_INT, dest, tag, comm);
144void MpiManager::send<float>(
float *buf,
int count,
int dest,
int tag, MPI_Comm comm)
149 MPI_Send(
static_cast<void*
>(buf), count, MPI_FLOAT, dest, tag, comm);
153void MpiManager::send<double>(
double *buf,
int count,
int dest,
int tag, MPI_Comm comm)
158 MPI_Send(
static_cast<void*
>(buf), count, MPI_DOUBLE, dest, tag, comm);
162void MpiManager::sendInit<double>(
double *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm 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);
194void MpiManager::sendInit<int>(
int *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
197 MPI_Send_init(buf, count, MPI_INT, dest, tag, comm, request);
202void MpiManager::sendInit<bool>(
bool *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
205 MPI_Send_init(
static_cast<void*
>(buf), count, MPI_BYTE, dest, tag, comm, request);
210void MpiManager::iSend<bool>
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);
219void MpiManager::iSend<char>
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);
237void MpiManager::iSend<int>
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);
264void MpiManager::iSend<float>
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);
273void MpiManager::iSend<double>
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);
282void MpiManager::iSend<long double>
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);
292void MpiManager::ibSend<bool>
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);
301void MpiManager::ibSend<char>
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);
310void MpiManager::ibSend<int>
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);
319void MpiManager::ibSend<float>
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);
328void MpiManager::ibSend<double>
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);
364void MpiManager::receive<bool>(
bool *buf,
int count,
int source,
int tag, MPI_Comm comm)
370 MPI_Recv(
static_cast<void*
>(buf), count, MPI_BYTE, source, tag, comm, &status);
375void MpiManager::receive<char>(
char *buf,
int count,
int source,
int tag, MPI_Comm comm)
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);
395void MpiManager::receive<int>(
int *buf,
int count,
int source,
int tag, MPI_Comm comm)
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);
425void MpiManager::receive<float>(
float *buf,
int count,
int source,
int tag, MPI_Comm comm)
431 MPI_Recv(
static_cast<void*
>(buf), count, MPI_FLOAT, source, tag, comm, &status);
435void MpiManager::receive<double>(
double *buf,
int count,
int source,
int tag, MPI_Comm comm)
441 MPI_Recv(
static_cast<void*
>(buf), count, MPI_DOUBLE, source, tag, comm, &status);
445void MpiManager::receive<long double>(
long double *buf,
int count,
int source,
int tag, MPI_Comm comm)
451 MPI_Recv(
static_cast<void*
>(buf), count, MPI_LONG_DOUBLE, source, tag, comm, &status);
455void MpiManager::sendToMaster<bool>(
bool* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
461 send(sendBuf, sendCount, 0);
464 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
469void MpiManager::sendToMaster<char>(
char* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
475 send(sendBuf, sendCount, 0);
478 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
483void MpiManager::sendToMaster<int>(
int* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
489 send(sendBuf, sendCount, 0);
492 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
497void MpiManager::sendToMaster<float>(
float* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
503 send(sendBuf, sendCount, 0);
506 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
511void MpiManager::sendToMaster<double>(
double* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
517 send(sendBuf, sendCount, 0);
520 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
525void MpiManager::recvInit<double>(
double *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
528 MPI_Recv_init(buf, count, MPI_DOUBLE, dest, tag, comm, request);
533void MpiManager::recvInit<int>(
int *buf,
int count,
int dest, MPI_Request* request,
int tag, MPI_Comm comm)
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);
549void MpiManager::iRecv<bool>(
bool *buf,
int count,
int source, MPI_Request* request,
int tag, MPI_Comm comm)
552 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_BYTE, source, tag, comm, request);
557void MpiManager::iRecv<char>(
char *buf,
int count,
int source, MPI_Request* request,
int tag, MPI_Comm comm)
560 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_CHAR, source, tag, comm, request);
565void MpiManager::iRecv<int>(
int *buf,
int count,
int source, MPI_Request* request,
int tag, MPI_Comm comm)
568 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_INT, source, tag, comm, request);
573void MpiManager::iRecv<float>(
float *buf,
int count,
int source, MPI_Request* request,
int tag, MPI_Comm comm)
576 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_FLOAT, source, tag, comm, request);
581void MpiManager::iRecv<double>(
double *buf,
int count,
int source, MPI_Request* request,
int tag, MPI_Comm comm)
584 MPI_Irecv(
static_cast<void*
>(buf), count, MPI_DOUBLE, source, tag, comm, request);
589void MpiManager::sendRecv<bool>
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);
605void MpiManager::sendRecv<char>
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);
621void MpiManager::sendRecv<int>
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);
637void MpiManager::sendRecv<float>
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);
653void MpiManager::sendRecv<long>
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);
669void MpiManager::sendRecv<double>
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);
685void MpiManager::sendRecv<long double>
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);
701void MpiManager::scatterv<bool>(
bool* sendBuf,
int* sendCounts,
int* displs,
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);
714void MpiManager::scatterv<char>(
char* sendBuf,
int* sendCounts,
int* displs,
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);
727void MpiManager::scatterv<int>(
int *sendBuf,
int* sendCounts,
int* displs,
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);
740void MpiManager::scatterv<float>(
float *sendBuf,
int* sendCounts,
int* displs,
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);
753void MpiManager::scatterv<double>(
double *sendBuf,
int* sendCounts,
int* displs,
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);
766void MpiManager::gather<int>(
int* sendBuf,
int sendCount,
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,
779void MpiManager::gatherv<bool>(
bool* sendBuf,
int sendCount,
780 bool* recvBuf,
int* recvCounts,
int* displs,
781 int root, MPI_Comm comm)
786 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_BYTE,
787 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_BYTE,
792void MpiManager::gatherv<char>(
char* sendBuf,
int sendCount,
793 char* recvBuf,
int* recvCounts,
int* displs,
794 int root, MPI_Comm comm)
799 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_CHAR,
800 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_CHAR,
805void MpiManager::gatherv<int>(
int* sendBuf,
int sendCount,
806 int* recvBuf,
int* recvCounts,
int* displs,
807 int root, MPI_Comm comm)
812 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_INT,
813 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_INT,
818void MpiManager::gatherv<float>(
float* sendBuf,
int sendCount,
819 float* recvBuf,
int* recvCounts,
int* displs,
820 int root, MPI_Comm comm)
825 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_FLOAT,
826 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_FLOAT,
831void MpiManager::gatherv<double>(
double* sendBuf,
int sendCount,
832 double* recvBuf,
int* recvCounts,
int* displs,
833 int root, MPI_Comm comm)
838 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_DOUBLE,
839 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_DOUBLE,
844void MpiManager::gatherv<std::size_t>(std::size_t* sendBuf,
int sendCount,
845 std::size_t* recvBuf,
int* recvCounts,
int* displs,
846 int root, MPI_Comm comm)
851 MPI_Gatherv(
static_cast<void*
>(sendBuf), sendCount, MPI_UNSIGNED_LONG,
852 static_cast<void*
>(recvBuf), recvCounts, displs, MPI_UNSIGNED_LONG,
857void MpiManager::bCast<bool>(
bool* sendBuf,
int sendCount,
int root, MPI_Comm comm)
862 MPI_Bcast(
static_cast<void*
>(sendBuf),
863 sendCount, MPI_BYTE, root, comm);
867void MpiManager::bCast<char>(
char* sendBuf,
int sendCount,
int root, MPI_Comm comm)
872 MPI_Bcast(
static_cast<void*
>(sendBuf),
873 sendCount, MPI_CHAR, root, comm);
877void MpiManager::bCast<unsigned char>(
unsigned char* sendBuf,
int sendCount,
int root, MPI_Comm comm)
882 MPI_Bcast(
static_cast<void*
>(sendBuf),
883 sendCount, MPI_UNSIGNED_CHAR, root, comm);
887void MpiManager::bCast<int>(
int* sendBuf,
int sendCount,
int root, MPI_Comm comm)
892 MPI_Bcast(
static_cast<void*
>(sendBuf),
893 sendCount, MPI_INT, root, comm);
897void MpiManager::bCast<unsigned long>(
unsigned long* sendBuf,
int sendCount,
int root, MPI_Comm comm)
902 MPI_Bcast(
static_cast<void*
>(sendBuf),
903 sendCount, MPI_UNSIGNED_LONG, root, comm);
907void MpiManager::bCast<float>(
float* sendBuf,
int sendCount,
int root, MPI_Comm comm)
912 MPI_Bcast(
static_cast<void*
>(sendBuf),
913 sendCount, MPI_FLOAT, root, comm);
917void MpiManager::bCast<double>(
double* sendBuf,
int sendCount,
int root, MPI_Comm comm)
922 MPI_Bcast(
static_cast<void*
>(sendBuf),
923 sendCount, MPI_DOUBLE, root, comm);
928void MpiManager::bCast<std::string>(std::string* sendBuf,
int sendCount,
int root, MPI_Comm comm)
933 int length = (int) sendBuf->size();
934 MPI_Bcast(
static_cast<void*
>(&length), 1, MPI_INT, root, comm);
935 char* buffer =
new char[length+1];
936 if (getRank()==root) {
937 std::copy(sendBuf->c_str(), sendBuf->c_str()+length+1, buffer);
939 MPI_Bcast(
static_cast<void*
>(buffer), length+1, MPI_CHAR, root, comm);
940 if (getRank()!=root) {
947void MpiManager::bCast<bool>(
bool& sendVal,
int root, MPI_Comm comm)
952 MPI_Bcast(&sendVal, 1, MPI_BYTE, root, comm);
955void MpiManager::bCast<char>(
char& sendVal,
int root, MPI_Comm comm)
960 MPI_Bcast(&sendVal, 1, MPI_CHAR, root, comm);
964void MpiManager::bCast<unsigned char>(
unsigned char& sendVal,
int root, MPI_Comm comm)
969 MPI_Bcast(&sendVal, 1, MPI_UNSIGNED_CHAR, root, comm);
973void MpiManager::bCast<int>(
int& sendVal,
int root, MPI_Comm comm)
978 MPI_Bcast(&sendVal, 1, MPI_INT, root, comm);
982void MpiManager::bCast<unsigned long>(
unsigned long& sendVal,
int root, MPI_Comm comm)
987 MPI_Bcast(&sendVal, 1, MPI_UNSIGNED_LONG, root, comm);
991void MpiManager::bCast<float>(
float& sendVal,
int root, MPI_Comm comm)
996 MPI_Bcast(&sendVal, 1, MPI_FLOAT, root, comm);
1000void MpiManager::bCast<double>(
double& sendVal,
int root, MPI_Comm comm)
1005 MPI_Bcast(&sendVal, 1, MPI_DOUBLE, root, comm);
1009void MpiManager::bCastThroughMaster<bool>(
bool* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
1015 send(sendBuf, sendCount, 0);
1018 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1020 bCast(sendBuf, sendCount, 0);
1024void MpiManager::bCastThroughMaster<char>(
char* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
1030 send(sendBuf, sendCount, 0);
1033 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1035 bCast(sendBuf, sendCount, 0);
1039void MpiManager::bCastThroughMaster<int>(
int* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
1045 send(sendBuf, sendCount, 0);
1048 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1050 bCast(sendBuf, sendCount, 0);
1054void MpiManager::bCastThroughMaster<float>(
float* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
1060 send(sendBuf, sendCount, 0);
1063 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1065 bCast(sendBuf, sendCount, 0);
1069void MpiManager::bCastThroughMaster<double>(
double* sendBuf,
int sendCount,
bool iAmRoot, MPI_Comm comm)
1075 send(sendBuf, sendCount, 0);
1078 receive(sendBuf, sendCount, MPI_ANY_SOURCE);
1080 bCast(sendBuf, sendCount, 0);
1084void MpiManager::reduce<bool>(
bool& sendVal,
bool& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1089 MPI_Reduce(
static_cast<void*
>(&sendVal),
1090 static_cast<void*
>(&recvVal), 1, MPI_BYTE, op, root, comm);
1094void MpiManager::reduce<char>(
char& sendVal,
char& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1099 MPI_Reduce(
static_cast<void*
>(&sendVal),
1100 static_cast<void*
>(&recvVal), 1, MPI_CHAR, op, root, comm);
1104void MpiManager::reduce<int>(
int& sendVal,
int& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1109 MPI_Reduce(
static_cast<void*
>(&sendVal),
1110 static_cast<void*
>(&recvVal), 1, MPI_INT, op, root, comm);
1114void MpiManager::reduce<float>(
float& sendVal,
float& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1119 MPI_Reduce(
static_cast<void*
>(&sendVal),
1120 static_cast<void*
>(&recvVal), 1, MPI_FLOAT, op, root, comm);
1124void MpiManager::reduce<double>(
double& sendVal,
double& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1129 MPI_Reduce(
static_cast<void*
>(&sendVal),
1130 static_cast<void*
>(&recvVal), 1, MPI_DOUBLE, op, root, comm);
1134void MpiManager::reduce<std::size_t>(std::size_t& sendVal, std::size_t& recvVal, MPI_Op op,
int root, MPI_Comm comm)
1139 MPI_Reduce(
static_cast<void*
>(&sendVal),
1140 static_cast<void*
>(&recvVal), 1, MPI_UNSIGNED_LONG, op, root, comm);
1144void MpiManager::reduceVect<char>(std::vector<char>& sendVal, std::vector<char>& recvVal,
1145 MPI_Op op,
int root, MPI_Comm comm)
1150 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1151 static_cast<void*
>(&(recvVal[0])),
1152 sendVal.size(), MPI_CHAR, op, root, comm);
1156void MpiManager::reduceVect<int>(std::vector<int>& sendVal, std::vector<int>& recvVal,
1157 MPI_Op op,
int root, MPI_Comm comm)
1162 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1163 static_cast<void*
>(&(recvVal[0])),
1164 sendVal.size(), MPI_INT, op, root, comm);
1168void MpiManager::reduceVect<float>(std::vector<float>& sendVal, std::vector<float>& recvVal,
1169 MPI_Op op,
int root, MPI_Comm comm)
1174 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1175 static_cast<void*
>(&(recvVal[0])),
1176 sendVal.size(), MPI_FLOAT, op, root, comm);
1180void MpiManager::reduceVect<double>(std::vector<double>& sendVal, std::vector<double>& recvVal,
1181 MPI_Op op,
int root, MPI_Comm comm)
1186 MPI_Reduce(
static_cast<void*
>(&(sendVal[0])),
1187 static_cast<void*
>(&(recvVal[0])),
1188 sendVal.size(), MPI_DOUBLE, op, root, comm);
1192void MpiManager::reduceAndBcast<bool>(
bool& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1198 MPI_Reduce(
static_cast<void*
>(&reductVal),
static_cast<void*
>(&recvVal), 1, MPI_BYTE, op, root, comm);
1199 reductVal = recvVal;
1200 MPI_Bcast(&reductVal, 1, MPI_BYTE, root, comm);
1205void MpiManager::reduceAndBcast<char>(
char& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1211 MPI_Reduce(&reductVal, &recvVal, 1, MPI_CHAR, op, root, comm);
1212 reductVal = recvVal;
1213 MPI_Bcast(&reductVal, 1, MPI_CHAR, root, comm);
1218void MpiManager::reduceAndBcast<int>(
int& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1224 MPI_Reduce(&reductVal, &recvVal, 1, MPI_INT, op, root, comm);
1225 reductVal = recvVal;
1226 MPI_Bcast(&reductVal, 1, MPI_INT, root, comm);
1231void MpiManager::reduceAndBcast<float>(
float& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1237 MPI_Reduce(&reductVal, &recvVal, 1, MPI_FLOAT, op, root, comm);
1238 reductVal = recvVal;
1239 MPI_Bcast(&reductVal, 1, MPI_FLOAT, root, comm);
1244void MpiManager::reduceAndBcast<double>(
double& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1250 MPI_Reduce(&reductVal, &recvVal, 1, MPI_DOUBLE, op, root, comm);
1251 reductVal = recvVal;
1252 MPI_Bcast(&reductVal, 1, MPI_DOUBLE, root, comm);
1257void MpiManager::reduceAndBcast<long double>(
long double& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1262 long double recvVal;
1263 MPI_Reduce(&reductVal, &recvVal, 1, MPI_LONG_DOUBLE, op, root, comm);
1264 reductVal = recvVal;
1265 MPI_Bcast(&reductVal, 1, MPI_LONG_DOUBLE, root, comm);
1270void MpiManager::reduceAndBcast<long>(
long& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1276 MPI_Reduce(&reductVal, &recvVal, 1, MPI_LONG, op, root, comm);
1277 reductVal = recvVal;
1278 MPI_Bcast(&reductVal, 1, MPI_LONG, root, comm);
1283void MpiManager::reduceAndBcast<unsigned long>(
unsigned long& reductVal, MPI_Op op,
int root, MPI_Comm comm)
1288 unsigned long recvVal;
1289 MPI_Reduce(&reductVal, &recvVal, 1, MPI_UNSIGNED_LONG, op, root, comm);
1290 reductVal = recvVal;
1291 MPI_Bcast(&reductVal, 1, MPI_UNSIGNED_LONG, root, comm);
1300 MPI_Wait(request, status);
1305 if (!ok || mpiNbHelper.
get_size() == 0) {
1318 std::swap(_size, rhs._size);
1319 std::swap(_mpiRequest, rhs._mpiRequest);
1320 std::swap(_mpiStatus, rhs._mpiStatus);
1326 _mpiRequest.reset(
new MPI_Request[n] { });
1327 _mpiStatus.reset(
new MPI_Status[n] { });
1344 return &_mpiRequest[i];
1350 return &_mpiStatus[i];
Wrapper functions that simplify the use of MPI.
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.
double getTime() const
Returns universal MPI-time in seconds.
bool isMainProcessor() const
Tells whether current processor is main processor.
void synchronizeIO(unsigned tDelay=100, MPI_Comm comm=MPI_COMM_WORLD)
Synchronizes the processes and wait to ensure correct cout order.
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 waitAll(MpiNonBlockingHelper &mpiNbHelper)
Complete a series of non-blocking MPI operations.
void barrier(MPI_Comm comm=MPI_COMM_WORLD)
Synchronizes the processes.
void init(int *argc, char ***argv, bool verbose=true)
Initializes the mpi manager.
int bossId() const
Returns process ID of main processor.
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)