42 #ifndef TPETRA_DISTRIBUTOR_HPP
43 #define TPETRA_DISTRIBUTOR_HPP
46 #include <Teuchos_as.hpp>
47 #include <Teuchos_Describable.hpp>
48 #include <Teuchos_ParameterListAcceptorDefaultBase.hpp>
49 #include <Teuchos_VerboseObject.hpp>
60 #ifdef TPETRA_DISTRIBUTOR_TIMERS
61 # undef TPETRA_DISTRIBUTOR_TIMERS
62 #endif // TPETRA_DISTRIBUTOR_TIMERS
72 enum EDistributorSendType {
84 DistributorSendTypeEnumToString (EDistributorSendType sendType);
164 public Teuchos::Describable,
165 public Teuchos::ParameterListAcceptorDefaultBase,
166 public Teuchos::VerboseObject<Distributor> {
178 explicit Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm);
189 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
190 const Teuchos::RCP<Teuchos::FancyOStream>& out);
204 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
205 const Teuchos::RCP<Teuchos::ParameterList>& plist);
221 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
222 const Teuchos::RCP<Teuchos::FancyOStream>& out,
223 const Teuchos::RCP<Teuchos::ParameterList>& plist);
312 template <
class Ordinal>
315 const ArrayView<const int>& remoteNodeIDs,
316 Array<Ordinal>& exportIDs,
317 Array<int>& exportNodeIDs);
412 template <
class Packet>
416 const ArrayView<Packet> &imports);
439 template <
class Packet>
442 const ArrayView<size_t> &numExportPacketsPerLID,
443 const ArrayView<Packet> &imports,
444 const ArrayView<size_t> &numImportPacketsPerLID);
470 template <
class Packet>
472 doPosts (
const ArrayRCP<const Packet> &exports,
474 const ArrayRCP<Packet> &imports);
494 template <
class Packet>
496 doPosts (
const ArrayRCP<const Packet> &exports,
497 const ArrayView<size_t> &numExportPacketsPerLID,
498 const ArrayRCP<Packet> &imports,
499 const ArrayView<size_t> &numImportPacketsPerLID);
513 template <
class Packet>
517 const ArrayView<Packet> &imports);
523 template <
class Packet>
526 const ArrayView<size_t> &numExportPacketsPerLID,
527 const ArrayView<Packet> &imports,
528 const ArrayView<size_t> &numImportPacketsPerLID);
534 template <
class Packet>
538 const ArrayRCP<Packet> &imports);
544 template <
class Packet>
547 const ArrayView<size_t> &numExportPacketsPerLID,
548 const ArrayRCP<Packet> &imports,
549 const ArrayView<size_t> &numImportPacketsPerLID);
567 void describe (Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default)
const;
573 RCP<const Comm<int> > comm_;
576 Teuchos::RCP<Teuchos::FancyOStream> out_;
582 Details::EDistributorSendType sendType_;
585 bool barrierBetween_;
619 Array<int> imagesTo_;
629 Array<size_t> startsTo_;
636 Array<size_t> lengthsTo_;
641 size_t maxSendLength_;
658 Array<size_t> indicesTo_;
677 size_t totalReceiveLength_;
684 Array<size_t> lengthsFrom_;
691 Array<int> imagesFrom_;
698 Array<size_t> startsFrom_;
706 Array<size_t> indicesFrom_;
714 Array<RCP<Teuchos::CommRequest<int> > > requests_;
720 mutable RCP<Distributor> reverseDistributor_;
722 #ifdef TPETRA_DISTRIBUTOR_TIMERS
723 Teuchos::RCP<Teuchos::Time> timer_doPosts3_;
724 Teuchos::RCP<Teuchos::Time> timer_doPosts4_;
725 Teuchos::RCP<Teuchos::Time> timer_doWaits_;
726 Teuchos::RCP<Teuchos::Time> timer_doPosts3_recvs_;
727 Teuchos::RCP<Teuchos::Time> timer_doPosts4_recvs_;
728 Teuchos::RCP<Teuchos::Time> timer_doPosts3_barrier_;
729 Teuchos::RCP<Teuchos::Time> timer_doPosts4_barrier_;
730 Teuchos::RCP<Teuchos::Time> timer_doPosts3_sends_;
731 Teuchos::RCP<Teuchos::Time> timer_doPosts4_sends_;
735 #endif // TPETRA_DISTRIBUTOR_TIMERS
748 bool useDistinctTags_;
754 int getTag (
const int pathTag)
const;
770 init (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
771 const Teuchos::RCP<Teuchos::ParameterList>& plist);
783 void computeReceives ();
797 template <
class Ordinal>
798 void computeSends (
const ArrayView<const Ordinal> &importIDs,
799 const ArrayView<const int> &importNodeIDs,
800 Array<Ordinal> &exportIDs,
801 Array<int> &exportNodeIDs);
804 void createReverseDistributor()
const;
809 template <
class Packet>
813 const ArrayView<Packet>& imports)
817 using Teuchos::ArrayRCP;
819 TEUCHOS_TEST_FOR_EXCEPTION(requests_.size() != 0, std::runtime_error,
820 Teuchos::typeName(*
this) <<
"::doPostsAndWaits(): There are "
821 << requests_.size() <<
" outstanding nonblocking messages pending. It is "
822 "incorrect to call doPostsAndWaits with posts outstanding.");
831 typedef typename ArrayRCP<const Packet>::size_type size_type;
834 ArrayRCP<const Packet> exportsArcp (exports.getRawPtr(), as<size_type> (0),
835 exports.size(),
false);
850 arcp<Packet> (imports.getRawPtr(), 0, imports.size(),
false));
854 template <
class Packet>
857 const ArrayView<size_t> &numExportPacketsPerLID,
858 const ArrayView<Packet> &imports,
859 const ArrayView<size_t> &numImportPacketsPerLID)
862 using Teuchos::ArrayRCP;
865 TEUCHOS_TEST_FOR_EXCEPTION(requests_.size() != 0, std::runtime_error,
866 Teuchos::typeName(*
this) <<
"::doPostsAndWaits(): There are "
867 << requests_.size() <<
" outstanding nonblocking messages pending. It is "
868 "incorrect to call doPostsAndWaits with posts outstanding.");
881 typedef typename ArrayRCP<const Packet>::size_type size_type;
882 ArrayRCP<const Packet> exportsArcp (exports.getRawPtr(), as<size_type> (0),
883 exports.size(),
false);
889 numExportPacketsPerLID,
890 arcp<Packet> (imports.getRawPtr(), 0, imports.size(),
false),
891 numImportPacketsPerLID);
896 template <
class Packet>
898 doPosts (
const ArrayRCP<const Packet>& exports,
900 const ArrayRCP<Packet>& imports)
902 using Teuchos::Array;
904 using Teuchos::FancyOStream;
905 using Teuchos::includesVerbLevel;
906 using Teuchos::ireceive;
907 using Teuchos::isend;
908 using Teuchos::OSTab;
909 using Teuchos::readySend;
911 using Teuchos::ssend;
912 using Teuchos::TypeNameTraits;
913 using Teuchos::typeName;
915 typedef Array<size_t>::size_type size_type;
917 Teuchos::OSTab tab (out_);
919 #ifdef TPETRA_DISTRIBUTOR_TIMERS
920 Teuchos::TimeMonitor timeMon (*timer_doPosts3_);
921 #endif // TPETRA_DISTRIBUTOR_TIMERS
925 const Details::EDistributorSendType sendType = sendType_;
926 const bool doBarrier = barrierBetween_;
954 TEUCHOS_TEST_FOR_EXCEPTION(
955 sendType == Details::DISTRIBUTOR_RSEND && ! doBarrier,
956 std::logic_error,
"Ready send implementation requires a barrier between "
957 "posting receives and posting ready sends. This should have been checked "
958 "before. Please report this bug to the Tpetra developers.");
960 const int myImageID = comm_->getRank();
961 size_t selfReceiveOffset = 0;
963 #ifdef HAVE_TEUCHOS_DEBUG
965 const size_t totalNumImportPackets = totalReceiveLength_ * numPackets;
966 TEUCHOS_TEST_FOR_EXCEPTION(as<size_t> (imports.size ()) != totalNumImportPackets,
967 std::runtime_error, typeName (*
this) <<
"::doPosts(): imports must be "
968 "large enough to store the imported data. imports.size() = "
969 << imports.size() <<
", but total number of import packets = "
970 << totalNumImportPackets <<
".");
971 #endif // HAVE_TEUCHOS_DEBUG
978 const int pathTag = 0;
979 const int tag = this->getTag (pathTag);
982 TEUCHOS_TEST_FOR_EXCEPTION(
983 requests_.size () != 0, std::logic_error,
"doPosts(3): Process "
984 << myImageID <<
": requests_.size() = " << requests_.size ()
986 std::ostringstream os;
987 os << myImageID <<
": doPosts(3,"
988 << (indicesTo_.empty () ?
"fast" :
"slow") <<
")" << endl;
1005 const size_type actualNumReceives = as<size_type> (numReceives_) +
1006 as<size_type> (selfMessage_ ? 1 : 0);
1007 requests_.resize (0);
1015 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1016 Teuchos::TimeMonitor timeMonRecvs (*timer_doPosts3_recvs_);
1017 #endif // TPETRA_DISTRIBUTOR_TIMERS
1019 size_t curBufferOffset = 0;
1020 for (size_type i = 0; i < actualNumReceives; ++i) {
1021 if (imagesFrom_[i] != myImageID) {
1029 ArrayRCP<Packet> recvBuf =
1030 imports.persistingView (curBufferOffset, lengthsFrom_[i]*numPackets);
1031 requests_.push_back (ireceive<int, Packet> (recvBuf, imagesFrom_[i],
1034 std::ostringstream os;
1035 os << myImageID <<
": doPosts(3,"
1036 << (indicesTo_.empty () ?
"fast" :
"slow") <<
"): "
1037 <<
"Posted irecv from Proc " << imagesFrom_[i] <<
" with "
1038 "specified tag " << tag << endl;
1043 selfReceiveOffset = curBufferOffset;
1045 curBufferOffset += lengthsFrom_[i]*numPackets;
1050 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1051 Teuchos::TimeMonitor timeMonBarrier (*timer_doPosts3_barrier_);
1052 #endif // TPETRA_DISTRIBUTOR_TIMERS
1061 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1062 Teuchos::TimeMonitor timeMonSends (*timer_doPosts3_sends_);
1063 #endif // TPETRA_DISTRIBUTOR_TIMERS
1070 size_t numBlocks = numSends_ + selfMessage_;
1071 size_t imageIndex = 0;
1072 while ((imageIndex < numBlocks) && (imagesTo_[imageIndex] < myImageID)) {
1075 if (imageIndex == numBlocks) {
1080 size_t selfIndex = 0;
1082 if (indicesTo_.empty()) {
1084 std::ostringstream os;
1085 os << myImageID <<
": doPosts(3,fast): posting sends" << endl;
1091 for (
size_t i = 0; i < numBlocks; ++i) {
1092 size_t p = i + imageIndex;
1093 if (p > (numBlocks - 1)) {
1097 if (imagesTo_[p] != myImageID) {
1098 ArrayView<const Packet> tmpSend =
1099 exports.view (startsTo_[p]*numPackets, lengthsTo_[p]*numPackets);
1101 if (sendType == Details::DISTRIBUTOR_SEND) {
1102 send<int, Packet> (tmpSend.getRawPtr (),
1103 as<int> (tmpSend.size ()),
1104 imagesTo_[p], tag, *comm_);
1106 else if (sendType == Details::DISTRIBUTOR_ISEND) {
1107 ArrayRCP<const Packet> tmpSendBuf =
1108 exports.persistingView (startsTo_[p] * numPackets,
1109 lengthsTo_[p] * numPackets);
1110 requests_.push_back (isend<int, Packet> (tmpSendBuf, imagesTo_[p],
1113 else if (sendType == Details::DISTRIBUTOR_RSEND) {
1114 readySend<int, Packet> (tmpSend.getRawPtr (),
1115 as<int> (tmpSend.size ()),
1116 imagesTo_[p], tag, *comm_);
1118 else if (sendType == Details::DISTRIBUTOR_SSEND) {
1119 ssend<int, Packet> (tmpSend.getRawPtr (),
1120 as<int> (tmpSend.size ()),
1121 imagesTo_[p], tag, *comm_);
1123 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Tpetra::"
1124 "Distributor (3 args): Invalid send type. We should never get "
1125 "here. Please report this bug to the Tpetra developers.");
1129 std::ostringstream os;
1130 os << myImageID <<
": doPosts(3,fast): "
1131 <<
"Posted send to Proc " << imagesTo_[i]
1132 <<
" w/ specified tag " << tag << endl;
1149 std::copy (exports.begin()+startsTo_[selfNum]*numPackets,
1150 exports.begin()+startsTo_[selfNum]*numPackets+lengthsTo_[selfNum]*numPackets,
1151 imports.begin()+selfReceiveOffset);
1154 std::ostringstream os;
1155 os << myImageID <<
": doPosts(3,fast) done" << endl;
1161 std::ostringstream os;
1162 os << myImageID <<
": doPosts(3,slow): posting sends" << endl;
1168 ArrayRCP<Packet> sendArray (maxSendLength_ * numPackets);
1170 TEUCHOS_TEST_FOR_EXCEPTION(
1171 sendType == Details::DISTRIBUTOR_ISEND, std::logic_error,
1172 "Tpetra::Distributor::doPosts<" << TypeNameTraits<Packet>::name()
1173 <<
"> (3-argument version):" << endl
1174 <<
"The \"send buffer\" code path doesn't currently work with nonblocking sends.");
1176 for (
size_t i = 0; i < numBlocks; ++i) {
1177 size_t p = i + imageIndex;
1178 if (p > (numBlocks - 1)) {
1182 if (imagesTo_[p] != myImageID) {
1183 typename ArrayView<const Packet>::iterator srcBegin, srcEnd;
1184 size_t sendArrayOffset = 0;
1185 size_t j = startsTo_[p];
1186 for (
size_t k = 0; k < lengthsTo_[p]; ++k, ++j) {
1187 srcBegin = exports.begin() + indicesTo_[j]*numPackets;
1188 srcEnd = srcBegin + numPackets;
1189 std::copy (srcBegin, srcEnd, sendArray.begin()+sendArrayOffset);
1190 sendArrayOffset += numPackets;
1192 ArrayView<const Packet> tmpSend =
1193 sendArray.view (0, lengthsTo_[p]*numPackets);
1195 if (sendType == Details::DISTRIBUTOR_SEND) {
1196 send<int, Packet> (tmpSend.getRawPtr (),
1197 as<int> (tmpSend.size ()),
1198 imagesTo_[p], tag, *comm_);
1200 else if (sendType == Details::DISTRIBUTOR_ISEND) {
1201 ArrayRCP<const Packet> tmpSendBuf =
1202 sendArray.persistingView (0, lengthsTo_[p] * numPackets);
1203 requests_.push_back (isend<int, Packet> (tmpSendBuf, imagesTo_[p],
1206 else if (sendType == Details::DISTRIBUTOR_RSEND) {
1207 readySend<int, Packet> (tmpSend.getRawPtr (),
1208 as<int> (tmpSend.size ()),
1209 imagesTo_[p], tag, *comm_);
1211 else if (sendType == Details::DISTRIBUTOR_SSEND) {
1212 ssend<int, Packet> (tmpSend.getRawPtr (),
1213 as<int> (tmpSend.size ()),
1214 imagesTo_[p], tag, *comm_);
1217 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Tpetra::"
1218 "Distributor (3 args): Invalid send type. We should never get "
1219 "here. Please report this bug to the Tpetra developers.");
1223 std::ostringstream os;
1224 os << myImageID <<
": doPosts(3,slow): "
1225 <<
"Posted send to Proc " << imagesTo_[i]
1226 <<
" w/ specified tag " << tag << endl;
1232 selfIndex = startsTo_[p];
1237 for (
size_t k = 0; k < lengthsTo_[selfNum]; ++k) {
1238 std::copy (exports.begin()+indicesTo_[selfIndex]*numPackets,
1239 exports.begin()+indicesTo_[selfIndex]*numPackets + numPackets,
1240 imports.begin() + selfReceiveOffset);
1242 selfReceiveOffset += numPackets;
1246 std::ostringstream os;
1247 os << myImageID <<
": doPosts(3,slow) done" << endl;
1253 template <
class Packet>
1256 const ArrayView<size_t>& numExportPacketsPerLID,
1257 const ArrayRCP<Packet>& imports,
1258 const ArrayView<size_t>& numImportPacketsPerLID)
1260 using Teuchos::Array;
1262 using Teuchos::ireceive;
1263 using Teuchos::isend;
1264 using Teuchos::readySend;
1265 using Teuchos::send;
1266 using Teuchos::ssend;
1267 using Teuchos::TypeNameTraits;
1268 #ifdef HAVE_TEUCHOS_DEBUG
1269 using Teuchos::OSTab;
1270 #endif // HAVE_TEUCHOS_DEBUG
1272 typedef Array<size_t>::size_type size_type;
1274 Teuchos::OSTab tab (out_);
1276 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1277 Teuchos::TimeMonitor timeMon (*timer_doPosts4_);
1278 #endif // TPETRA_DISTRIBUTOR_TIMERS
1282 const Details::EDistributorSendType sendType = sendType_;
1283 const bool doBarrier = barrierBetween_;
1309 TEUCHOS_TEST_FOR_EXCEPTION(sendType == Details::DISTRIBUTOR_RSEND && ! doBarrier,
1310 std::logic_error,
"Ready send implementation requires a barrier between "
1311 "posting receives and posting ready sends. This should have been checked "
1312 "before. Please report this bug to the Tpetra developers.");
1314 const int myImageID = comm_->getRank();
1315 size_t selfReceiveOffset = 0;
1317 #ifdef HAVE_TEUCHOS_DEBUG
1319 size_t totalNumImportPackets = 0;
1320 for (
int ii = 0; ii < numImportPacketsPerLID.size(); ++ii) {
1321 totalNumImportPackets += numImportPacketsPerLID[ii];
1323 TEUCHOS_TEST_FOR_EXCEPTION(as<size_t> (imports.size ()) != totalNumImportPackets,
1324 std::runtime_error, Teuchos::typeName (*
this) <<
"::doPosts(): The "
1325 "imports array argument must be large enough to store the imported "
1326 "data. imports.size() = " << imports.size() <<
", but the total number "
1327 "of packets is " << totalNumImportPackets <<
".");
1328 #endif // HAVE_TEUCHOS_DEBUG
1335 const int pathTag = 1;
1336 const int tag = this->getTag (pathTag);
1339 TEUCHOS_TEST_FOR_EXCEPTION(
1340 requests_.size () != 0, std::logic_error,
"doPosts(4): Process "
1341 << myImageID <<
": requests_.size() = " << requests_.size ()
1343 std::ostringstream os;
1344 os << myImageID <<
": doPosts(4,"
1345 << (indicesTo_.empty () ?
"fast" :
"slow") <<
")" << endl;
1362 const size_type actualNumReceives = as<size_type> (numReceives_) +
1363 as<size_type> (selfMessage_ ? 1 : 0);
1364 requests_.resize (0);
1372 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1373 Teuchos::TimeMonitor timeMonRecvs (*timer_doPosts4_recvs_);
1374 #endif // TPETRA_DISTRIBUTOR_TIMERS
1376 size_t curBufferOffset = 0;
1377 size_t curLIDoffset = 0;
1378 for (size_type i = 0; i < actualNumReceives; ++i) {
1379 size_t totalPacketsFrom_i = 0;
1380 for (
size_t j = 0; j < lengthsFrom_[i]; ++j) {
1381 totalPacketsFrom_i += numImportPacketsPerLID[curLIDoffset+j];
1383 curLIDoffset += lengthsFrom_[i];
1384 if (imagesFrom_[i] != myImageID && totalPacketsFrom_i) {
1393 ArrayRCP<Packet> recvBuf =
1394 imports.persistingView (curBufferOffset, totalPacketsFrom_i);
1395 requests_.push_back (ireceive<int, Packet> (recvBuf, imagesFrom_[i],
1399 selfReceiveOffset = curBufferOffset;
1401 curBufferOffset += totalPacketsFrom_i;
1406 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1407 Teuchos::TimeMonitor timeMonBarrier (*timer_doPosts4_barrier_);
1408 #endif // TPETRA_DISTRIBUTOR_TIMERS
1417 #ifdef TPETRA_DISTRIBUTOR_TIMERS
1418 Teuchos::TimeMonitor timeMonSends (*timer_doPosts4_sends_);
1419 #endif // TPETRA_DISTRIBUTOR_TIMERS
1423 Array<size_t> sendPacketOffsets(numSends_,0), packetsPerSend(numSends_,0);
1424 size_t maxNumPackets = 0;
1425 size_t curPKToffset = 0;
1426 for (
size_t pp=0; pp<numSends_; ++pp) {
1427 sendPacketOffsets[pp] = curPKToffset;
1428 size_t numPackets = 0;
1429 for (
size_t j=startsTo_[pp]; j<startsTo_[pp]+lengthsTo_[pp]; ++j) {
1430 numPackets += numExportPacketsPerLID[j];
1432 if (numPackets > maxNumPackets) maxNumPackets = numPackets;
1433 packetsPerSend[pp] = numPackets;
1434 curPKToffset += numPackets;
1439 size_t numBlocks = numSends_+ selfMessage_;
1440 size_t imageIndex = 0;
1441 while ((imageIndex < numBlocks) && (imagesTo_[imageIndex] < myImageID)) {
1444 if (imageIndex == numBlocks) {
1449 size_t selfIndex = 0;
1451 if (indicesTo_.empty()) {
1453 std::ostringstream os;
1454 os << myImageID <<
": doPosts(4,fast): posting sends" << endl;
1460 for (
size_t i = 0; i < numBlocks; ++i) {
1461 size_t p = i + imageIndex;
1462 if (p > (numBlocks - 1)) {
1466 if (imagesTo_[p] != myImageID && packetsPerSend[p] > 0) {
1467 ArrayView<const Packet> tmpSend =
1468 exports.view (sendPacketOffsets[p], packetsPerSend[p]);
1470 if (sendType == Details::DISTRIBUTOR_SEND) {
1471 send<int, Packet> (tmpSend.getRawPtr (),
1472 as<int> (tmpSend.size ()),
1473 imagesTo_[p], tag, *comm_);
1475 else if (sendType == Details::DISTRIBUTOR_RSEND) {
1476 readySend<int, Packet> (tmpSend.getRawPtr (),
1477 as<int> (tmpSend.size ()),
1478 imagesTo_[p], tag, *comm_);
1480 else if (sendType == Details::DISTRIBUTOR_ISEND) {
1481 ArrayRCP<const Packet> tmpSendBuf =
1482 exports.persistingView (sendPacketOffsets[p], packetsPerSend[p]);
1483 requests_.push_back (isend<int, Packet> (tmpSendBuf, imagesTo_[p],
1486 else if (sendType == Details::DISTRIBUTOR_SSEND) {
1487 ssend<int, Packet> (tmpSend.getRawPtr (),
1488 as<int> (tmpSend.size ()),
1489 imagesTo_[p], tag, *comm_);
1492 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Tpetra::"
1493 "Distributor (4 args): Invalid send type. We should never get "
1494 "here. Please report this bug to the Tpetra developers.");
1503 std::copy (exports.begin()+sendPacketOffsets[selfNum],
1504 exports.begin()+sendPacketOffsets[selfNum]+packetsPerSend[selfNum],
1505 imports.begin()+selfReceiveOffset);
1508 std::ostringstream os;
1509 os << myImageID <<
": doPosts(4,fast) done" << endl;
1515 std::ostringstream os;
1516 os << myImageID <<
": doPosts(4,slow): posting sends" << endl;
1521 ArrayRCP<Packet> sendArray (maxNumPackets);
1523 TEUCHOS_TEST_FOR_EXCEPTION(
1524 sendType == Details::DISTRIBUTOR_ISEND, std::logic_error,
1525 "Tpetra::Distributor::doPosts<" << TypeNameTraits<Packet>::name()
1526 <<
"> (3-argument version):" << endl
1527 <<
"The \"send buffer\" code path may not necessarily work with nonblocking sends.");
1529 Array<size_t> indicesOffsets (numExportPacketsPerLID.size(), 0);
1531 for (
int j=0; j<numExportPacketsPerLID.size(); ++j) {
1532 indicesOffsets[j] = ioffset;
1533 ioffset += numExportPacketsPerLID[j];
1536 for (
size_t i = 0; i < numBlocks; ++i) {
1537 size_t p = i + imageIndex;
1538 if (p > (numBlocks - 1)) {
1542 if (imagesTo_[p] != myImageID) {
1543 typename ArrayView<const Packet>::iterator srcBegin, srcEnd;
1544 size_t sendArrayOffset = 0;
1545 size_t j = startsTo_[p];
1546 size_t numPacketsTo_p = 0;
1547 for (
size_t k = 0; k < lengthsTo_[p]; ++k, ++j) {
1548 srcBegin = exports.begin() + indicesOffsets[j];
1549 srcEnd = srcBegin + numExportPacketsPerLID[j];
1550 numPacketsTo_p += numExportPacketsPerLID[j];
1551 std::copy (srcBegin, srcEnd, sendArray.begin()+sendArrayOffset);
1552 sendArrayOffset += numExportPacketsPerLID[j];
1554 if (numPacketsTo_p > 0) {
1555 ArrayView<const Packet> tmpSend =
1556 sendArray.view (0, numPacketsTo_p);
1558 if (sendType == Details::DISTRIBUTOR_RSEND) {
1559 readySend<int, Packet> (tmpSend.getRawPtr (),
1560 as<int> (tmpSend.size ()),
1561 imagesTo_[p], tag, *comm_);
1563 else if (sendType == Details::DISTRIBUTOR_ISEND) {
1564 ArrayRCP<const Packet> tmpSendBuf =
1565 sendArray.persistingView (0, numPacketsTo_p);
1566 requests_.push_back (isend<int, Packet> (tmpSendBuf, imagesTo_[p],
1569 else if (sendType == Details::DISTRIBUTOR_SSEND) {
1570 ssend<int, Packet> (tmpSend.getRawPtr (),
1571 as<int> (tmpSend.size ()),
1572 imagesTo_[p], tag, *comm_);
1575 send<int, Packet> (tmpSend.getRawPtr (),
1576 as<int> (tmpSend.size ()),
1577 imagesTo_[p], tag, *comm_);
1583 selfIndex = startsTo_[p];
1588 for (
size_t k = 0; k < lengthsTo_[selfNum]; ++k) {
1589 std::copy (exports.begin()+indicesOffsets[selfIndex],
1590 exports.begin()+indicesOffsets[selfIndex]+numExportPacketsPerLID[selfIndex],
1591 imports.begin() + selfReceiveOffset);
1592 selfReceiveOffset += numExportPacketsPerLID[selfIndex];
1597 std::ostringstream os;
1598 os << myImageID <<
": doPosts(4,slow) done" << endl;
1604 template <
class Packet>
1608 const ArrayView<Packet>& imports)
1622 typedef typename ArrayRCP<const Packet>::size_type size_type;
1623 ArrayRCP<const Packet> exportsArcp (exports.getRawPtr(), as<size_type> (0),
1624 exports.size(),
false);
1631 arcp<Packet> (imports.getRawPtr (), 0, imports.size (),
false));
1635 template <
class Packet>
1638 const ArrayView<size_t> &numExportPacketsPerLID,
1639 const ArrayView<Packet> &imports,
1640 const ArrayView<size_t> &numImportPacketsPerLID)
1643 using Teuchos::arcp;
1644 using Teuchos::ArrayRCP;
1646 TEUCHOS_TEST_FOR_EXCEPTION(requests_.size() != 0, std::runtime_error,
1647 Teuchos::typeName(*
this) <<
"::doReversePostsAndWaits(): There are "
1648 << requests_.size() <<
" outstanding nonblocking messages pending. It is "
1649 "incorrect to call doReversePostsAndWaits with posts outstanding.");
1662 typedef typename ArrayRCP<const Packet>::size_type size_type;
1663 ArrayRCP<const Packet> exportsArcp (exports.getRawPtr (), as<size_type> (0),
1664 exports.size (),
false);
1666 numExportPacketsPerLID,
1667 arcp<Packet> (imports.getRawPtr (), 0, imports.size (),
false),
1668 numImportPacketsPerLID);
1672 template <
class Packet>
1676 const ArrayRCP<Packet>& imports)
1679 TEUCHOS_TEST_FOR_EXCEPTION(! indicesTo_.empty (), std::runtime_error,
1680 Teuchos::typeName (*
this) <<
"::doReversePosts(): Can only do reverse "
1681 "communication when original data are blocked by process.");
1682 if (reverseDistributor_.is_null ()) {
1683 createReverseDistributor ();
1685 reverseDistributor_->doPosts (exports, numPackets, imports);
1688 template <
class Packet>
1691 const ArrayView<size_t>& numExportPacketsPerLID,
1692 const ArrayRCP<Packet>& imports,
1693 const ArrayView<size_t>& numImportPacketsPerLID)
1696 TEUCHOS_TEST_FOR_EXCEPTION(! indicesTo_.empty (), std::runtime_error,
1697 Teuchos::typeName (*
this) <<
"::doReversePosts(): Can only do reverse "
1698 "communication when original data are blocked by process.");
1699 if (reverseDistributor_.is_null ()) {
1700 createReverseDistributor ();
1702 reverseDistributor_->doPosts (exports, numExportPacketsPerLID,
1703 imports, numImportPacketsPerLID);
1706 template <
class OrdinalType>
1708 computeSends (
const ArrayView<const OrdinalType> & importIDs,
1709 const ArrayView<const int> & importNodeIDs,
1710 Array<OrdinalType> & exportIDs,
1711 Array<int> & exportNodeIDs)
1723 Teuchos::OSTab tab (out_);
1725 const int myRank = comm_->getRank();
1727 std::ostringstream os;
1728 os << myRank <<
": computeSends" << endl;
1732 const size_t numImports = importNodeIDs.size();
1733 TEUCHOS_TEST_FOR_EXCEPTION(as<size_t> (importIDs.size ()) < numImports,
1734 std::invalid_argument,
"Tpetra::Distributor::computeSends: importNodeIDs."
1735 "size() = " << importNodeIDs.size () <<
" != importIDs.size() = "
1736 << importIDs.size () <<
".");
1738 Array<size_t> importObjs (2*numImports);
1740 for (
size_t i = 0; i < numImports; ++i ) {
1741 importObjs[2*i] = as<size_t> (importIDs[i]);
1742 importObjs[2*i+1] = as<size_t> (myRank);
1751 std::ostringstream os;
1752 os << myRank <<
": computeSends: tempPlan.createFromSends" << endl;
1755 numExports = tempPlan.createFromSends (importNodeIDs);
1756 if (numExports > 0) {
1757 exportIDs.resize(numExports);
1758 exportNodeIDs.resize(numExports);
1760 Array<size_t> exportObjs (tempPlan.getTotalReceiveLength () * 2);
1762 std::ostringstream os;
1763 os << myRank <<
": computeSends: tempPlan.doPostsAndWaits" << endl;
1766 tempPlan.doPostsAndWaits<
size_t> (importObjs (), 2, exportObjs ());
1769 for (
size_t i = 0; i < numExports; ++i) {
1770 exportIDs[i] = as<OrdinalType>(exportObjs[2*i]);
1771 exportNodeIDs[i] = exportObjs[2*i+1];
1775 std::ostringstream os;
1776 os << myRank <<
": computeSends done" << endl;
1781 template <
class OrdinalType>
1784 const ArrayView<const int> &remoteImageIDs,
1785 Array<OrdinalType> &exportGIDs,
1786 Array<int> &exportNodeIDs)
1790 Teuchos::OSTab tab (out_);
1791 const int myRank = comm_->getRank();
1794 *out_ << myRank <<
": createFromRecvs" << endl;
1797 #ifdef HAVE_TPETRA_DEBUG
1798 using Teuchos::outArg;
1799 using Teuchos::reduceAll;
1802 (remoteIDs.size () != remoteImageIDs.size ()) ? myRank : -1;
1803 int maxErrProc = -1;
1804 reduceAll<int, int> (*comm_, Teuchos::REDUCE_MAX, errProc, outArg (maxErrProc));
1805 TEUCHOS_TEST_FOR_EXCEPTION(maxErrProc != -1, std::runtime_error,
1806 Teuchos::typeName (*
this) <<
"::createFromRecvs(): lists of remote IDs "
1807 "and remote process IDs must have the same size on all participating "
1808 "processes. Maximum process ID with error: " << maxErrProc <<
".");
1809 #endif // HAVE_TPETRA_DEBUG
1811 computeSends (remoteIDs, remoteImageIDs, exportGIDs, exportNodeIDs);
1815 *out_ << myRank <<
": createFromRecvs done" << endl;
1821 #endif // TPETRA_DISTRIBUTOR_HPP
size_t getNumReceives() const
The number of processes from which we will receive data.
std::string description() const
A simple one-line description of this object.
ArrayView< const int > getImagesTo() const
Ranks of the processes to which this process will send values.
void doPosts(const ArrayRCP< const Packet > &exports, size_t numPackets, const ArrayRCP< Packet > &imports)
Post the data for a forward plan, but do not execute the waits yet.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
List of valid Distributor parameters.
void swap(Distributor &rhs)
Swap the contents of rhs with those of *this.
ArrayView< const size_t > getLengthsFrom() const
Number of values this process will receive from each process.
void doPostsAndWaits(const ArrayView< const Packet > &exports, size_t numPackets, const ArrayView< Packet > &imports)
Execute the (forward) communication plan.
bool hasSelfMessage() const
Whether the calling process will send or receive messages to itself.
Sets up and executes a communication plan for a Tpetra DistObject.
size_t getTotalReceiveLength() const
Total number of values this process will receive from other processes.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set Distributor parameters.
size_t createFromSends(const ArrayView< const int > &exportNodeIDs)
Set up Distributor using list of process ranks to which this process will send.
void doReversePosts(const ArrayRCP< const Packet > &exports, size_t numPackets, const ArrayRCP< Packet > &imports)
Post the data for a reverse plan, but do not execute the waits yet.
ArrayView< const size_t > getLengthsTo() const
Number of values this process will send to each process.
virtual ~Distributor()
Destructor (virtual for memory safety).
void doReversePostsAndWaits(const ArrayView< const Packet > &exports, size_t numPackets, const ArrayView< Packet > &imports)
Execute the reverse communication plan.
Stand-alone utility functions and macros.
ArrayView< const int > getImagesFrom() const
Ranks of the processes sending values to this process.
size_t getNumSends() const
The number of processes to which we will send data.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream.
size_t getMaxSendLength() const
Maximum number of values this process will send to another single process.
Array< std::string > distributorSendTypes()
Valid values for Distributor's "Send type" parameter.
void createFromRecvs(const ArrayView< const Ordinal > &remoteIDs, const ArrayView< const int > &remoteNodeIDs, Array< Ordinal > &exportIDs, Array< int > &exportNodeIDs)
Set up Distributor using list of process ranks from which to receive.
const RCP< Distributor > & getReverse() const
A reverse communication plan Distributor.
Distributor(const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Construct using the specified communicator and default parameters.