42 #ifndef TPETRA_IMPORT_DEF_HPP 43 #define TPETRA_IMPORT_DEF_HPP 45 #ifdef DOXYGEN_USE_ONLY 46 # include <Tpetra_Import_decl.hpp> 47 #endif // DOXYGEN_USE_ONLY 49 #include <Tpetra_Distributor.hpp> 50 #include <Tpetra_Map.hpp> 51 #include <Tpetra_ImportExportData.hpp> 53 #include <Tpetra_Export.hpp> 59 const bool tpetraImportDebugDefault =
false;
64 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 Import<LocalOrdinal,GlobalOrdinal,Node>::
69 bool debug = tpetraImportDebugDefault;
72 debug = plist->
get<
bool> (
"Debug");
76 ImportData_->distributor_.setParameterList (plist);
79 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 bool debug = tpetraImportDebugDefault;
96 debug = plist->
get<
bool> (
"Debug");
101 if (! out_.is_null ()) {
105 std::ostringstream os;
106 const int myRank = source->getComm ()->getRank ();
107 os << myRank <<
": Import ctor" << endl;
110 ImportData_ =
rcp (
new data_type (source, target, out_, plist));
113 setupSamePermuteRemote (remoteGIDs);
115 std::ostringstream os;
116 const int myRank = source->getComm ()->getRank ();
117 os << myRank <<
": Import ctor: " 118 <<
"setupSamePermuteRemote done" << endl;
121 if (source->isDistributed ()) {
122 setupExport (remoteGIDs);
125 std::ostringstream os;
126 const int myRank = source->getComm ()->getRank ();
127 os << myRank <<
": Import ctor: done" << endl;
130 if (! out_.is_null ()) {
135 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
140 debug_ (tpetraImportDebugDefault)
142 init (source, target, Teuchos::null);
145 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
151 debug_ (tpetraImportDebugDefault)
153 init (source, target, Teuchos::null);
156 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
161 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
162 debug_ (tpetraImportDebugDefault)
164 init (source, target, plist);
167 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 debug_ (tpetraImportDebugDefault)
176 init (source, target, plist);
179 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
182 : ImportData_ (rhs.ImportData_)
184 , debug_ (rhs.debug_)
187 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
190 : out_ (exporter.out_)
191 , debug_ (exporter.debug_)
193 if (! exporter.ExportData_.is_null ()) {
194 ImportData_ = exporter.ExportData_->reverseClone ();
198 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
202 const size_t numSameIDs,
211 out_ (out.
is_null () ? Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr)) : out),
212 debug_ (tpetraImportDebugDefault)
222 bool debug = tpetraImportDebugDefault;
225 debug = plist->
get<
bool> (
"Debug");
233 if (debug_ && ! out_.
is_null ()) {
234 std::ostringstream os;
235 const int myRank = source->
getComm ()->getRank ();
236 os << myRank <<
": Import expert ctor" << endl;
239 ImportData_ =
rcp (
new data_type (source, target, out_, plist));
241 ImportData_->numSameIDs_ = numSameIDs;
242 ImportData_->permuteToLIDs_.swap (permuteToLIDs);
243 ImportData_->permuteFromLIDs_.swap (permuteFromLIDs);
244 ImportData_->remoteLIDs_.swap (remoteLIDs);
245 ImportData_->distributor_.swap (distributor);
246 ImportData_->exportLIDs_.swap (exportLIDs);
247 ImportData_->exportPIDs_.swap (exportPIDs);
250 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
254 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
256 return ImportData_->numSameIDs_;
259 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 return ImportData_->permuteFromLIDs_.size();
264 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
267 return ImportData_->permuteFromLIDs_();
270 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
273 return ImportData_->permuteToLIDs_();
276 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
278 return ImportData_->remoteLIDs_.size();
281 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
284 return ImportData_->remoteLIDs_();
287 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
289 return ImportData_->exportLIDs_.size();
292 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
295 return ImportData_->exportLIDs_();
298 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301 return ImportData_->exportPIDs_();
304 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
307 return ImportData_->source_;
310 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 return ImportData_->target_;
316 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
319 return ImportData_->distributor_;
322 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
327 ImportData_ = rhs.ImportData_;
332 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
337 using Teuchos::getFancyOStream;
339 using Teuchos::rcpFromRef;
344 const int myImageID = comm->getRank ();
345 const int numImages = comm->getSize ();
346 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
347 if (myImageID == imageCtr) {
349 if (myImageID == 0) {
350 os <<
"Import Data Members:" << endl;
352 os <<
"Image ID : " << myImageID << endl;
371 const bool printMaps =
false;
373 if (myImageID == 0) {
374 os << endl << endl <<
"Source Map:" << endl << std::flush;
380 if (myImageID == 0) {
381 os << endl << endl <<
"Target Map:" << endl << std::flush;
391 if (myImageID == 0) {
392 os << endl << endl <<
"Distributor:" << endl << std::flush;
400 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
411 typedef LocalOrdinal LO;
412 typedef GlobalOrdinal GO;
419 #ifdef HAVE_TPETRA_DEBUG 423 const GO*
const rawSrcGids = sourceGIDs.
getRawPtr ();
424 const GO*
const rawTgtGids = targetGIDs.
getRawPtr ();
425 #endif // HAVE_TPETRA_DEBUG 426 const size_type numSrcGids = sourceGIDs.
size ();
427 const size_type numTgtGids = targetGIDs.
size ();
428 const size_type numGids = std::min (numSrcGids, numTgtGids);
436 size_type numSameGids = 0;
437 for ( ; numSameGids < numGids && rawSrcGids[numSameGids] == rawTgtGids[numSameGids]; ++numSameGids)
439 ImportData_->numSameIDs_ = numSameGids;
451 Array<LO>& permuteToLIDs = ImportData_->permuteToLIDs_;
452 Array<LO>& permuteFromLIDs = ImportData_->permuteFromLIDs_;
453 Array<LO>& remoteLIDs = ImportData_->remoteLIDs_;
455 const LO numTgtLids = as<LO> (numTgtGids);
458 for (LO tgtLid = numSameGids; tgtLid < numTgtLids; ++tgtLid) {
459 const GO curTargetGid = rawTgtGids[tgtLid];
463 if (srcLid != LINVALID) {
475 "::setupSamePermuteRemote(): Target has remote LIDs but Source is not " 476 "distributed globally." << std::endl
477 <<
"Importing to a submap of the target map.");
481 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
491 typedef LocalOrdinal LO;
492 typedef GlobalOrdinal GO;
499 std::ostringstream os;
500 const int myRank = source.
getComm ()->getRank ();
501 os << myRank <<
": Import::setupExport" << endl;
531 std::ostringstream os;
532 const int myRank = source.
getComm ()->getRank ();
533 os << myRank <<
": Import::setupExport: finished lookup" << endl;
538 "::setupExport(): the source Map wasn't able to figure out which process " 539 "owns one or more of the GIDs in the list of remote GIDs. This probably " 540 "means that there is at least one GID owned by some process in the target" 541 " Map which is not owned by any process in the source Map. (That is, the" 542 " source and target Maps do not contain the same set of GIDs globally.)");
548 const size_type numInvalidRemote =
549 std::count_if (remoteProcIDs.begin (), remoteProcIDs.end (),
550 std::bind1st (std::equal_to<int> (), -1));
553 if (numInvalidRemote == totalNumRemote) {
555 remoteProcIDs.clear ();
557 ImportData_->remoteLIDs_.clear();
562 size_type numValidRemote = 0;
563 #ifdef HAVE_TPETRA_DEBUG 566 GlobalOrdinal*
const remoteGIDsPtr = remoteGIDsView.
getRawPtr ();
567 #endif // HAVE_TPETRA_DEBUG 568 for (size_type r = 0; r < totalNumRemote; ++r) {
570 if (remoteProcIDs[r] != -1) {
571 remoteProcIDs[numValidRemote] = remoteProcIDs[r];
572 remoteGIDsPtr[numValidRemote] = remoteGIDsPtr[r];
573 ImportData_->remoteLIDs_[numValidRemote] = ImportData_->remoteLIDs_[r];
578 numValidRemote != totalNumRemote - numInvalidRemote, std::logic_error,
579 "Tpetra::Import::setupExport(): After removing invalid remote GIDs and" 580 " packing the valid remote GIDs, numValidRemote = " << numValidRemote
581 <<
" != totalNumRemote - numInvalidRemote = " 582 << totalNumRemote - numInvalidRemote
583 <<
". Please report this bug to the Tpetra developers.");
585 remoteProcIDs.resize (numValidRemote);
586 remoteGIDs.
resize (numValidRemote);
587 ImportData_->remoteLIDs_.resize (numValidRemote);
590 remoteGIDsView = remoteGIDs ();
597 sort3 (remoteProcIDs.begin (),
598 remoteProcIDs.end (),
599 remoteGIDsView.
begin (),
600 ImportData_->remoteLIDs_.begin ());
608 ImportData_->distributor_.createFromRecvs (remoteGIDsView ().
getConst (),
609 remoteProcIDs, exportGIDs,
610 ImportData_->exportPIDs_);
616 const size_type numExportIDs = exportGIDs.size ();
617 if (numExportIDs > 0) {
618 ImportData_->exportLIDs_.resize(numExportIDs);
622 for (size_type k = 0; k < numExportIDs; ++k) {
627 std::ostringstream os;
628 const int myRank = source.
getComm ()->getRank ();
629 os << myRank <<
": Import::setupExport: done" << endl;
634 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
648 using Teuchos::outArg;
649 using Teuchos::REDUCE_MIN;
651 typedef LocalOrdinal LO;
652 typedef GlobalOrdinal GO;
659 #ifdef HAVE_TPETRA_DEBUG 662 "Tpetra::Import::setUnion: The source Map of the input Import must be the " 663 "same as (in the sense of Map::isSameAs) the source Map of this Import.");
665 ! Details::congruent (* (tgtMap1->
getComm ()), * (tgtMap2->
getComm ())),
666 std::invalid_argument,
"Tpetra::Import::setUnion: " 667 "The target Maps must have congruent communicators.");
668 #endif // HAVE_TPETRA_DEBUG 676 if (! SortDetails::isAlreadySorted (gids1.begin (), gids1.end ())) {
677 gids1Copy.
reserve (gids1.size ());
678 gids1Copy.
assign (gids1.begin (), gids1.end ());
679 std::sort (gids1Copy.
begin (), gids1Copy.
end ());
680 gids1 = gids1Copy ();
682 if (! SortDetails::isAlreadySorted (gids2.
begin (), gids2.
end ())) {
685 std::sort (gids2Copy.
begin (), gids2Copy.
end ());
686 gids2 = gids2Copy ();
690 gidsUnion.
reserve (std::max (gids1.size (), gids2.
size ()));
691 std::set_union (gids1.begin (), gids1.end (), gids2.
begin (), gids2.
end (),
692 std::back_inserter (gidsUnion));
697 std::min_element (gidsUnion.
begin (), gidsUnion.
end ());
698 const GO myMinGid = (minPos == gidsUnion.
end ()) ? 0 : *minPos;
700 reduceAll<int, GO> (*comm, REDUCE_MIN, myMinGid, outArg (globalMinGid));
703 rcp (
new map_type (INVALID, gidsUnion (), globalMinGid,
705 return rcp (
new import_type (srcMap, unionMap));
708 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
713 return setUnionImpl (rhs);
717 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
729 using Teuchos::outArg;
730 using Teuchos::REDUCE_MIN;
732 typedef LocalOrdinal LO;
733 typedef GlobalOrdinal GO;
737 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 741 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 748 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 749 const int myRank = comm->getRank ();
750 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 752 #ifdef HAVE_TPETRA_DEBUG 755 "Tpetra::Import::setUnion: The source Map of the input Import must be the " 756 "same as (in the sense of Map::isSameAs) the source Map of this Import.");
758 ! Details::congruent (* (tgtMap1->
getComm ()), * (tgtMap2->
getComm ())),
759 std::invalid_argument,
"Tpetra::Import::setUnion: " 760 "The target Maps must have congruent communicators.");
761 #endif // HAVE_TPETRA_DEBUG 767 return rcp (
new import_type (*
this));
776 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 779 std::ostringstream os;
780 os << myRank <<
": srcGIDs: " <<
toString (srcGIDs) << endl;
781 os << myRank <<
": tgtGIDs1: " <<
toString (tgtGIDs1) << endl;
782 os << myRank <<
": tgtGIDs2: " <<
toString (tgtGIDs2) << endl;
786 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 798 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 805 cerr << myRank <<
": Computing \"same\" GIDs" << endl;
806 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 816 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 818 std::ostringstream os;
819 os << myRank <<
": same IDs for target Map 1: " <<
toString (sameGIDs1) << endl;
820 os << myRank <<
": same IDs for target Map 2: " <<
toString (sameGIDs2) << endl;
823 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 832 size_type numSameIDsUnion;
833 bool tgtMap1HadMaxSameGIDs;
834 if (numSameGIDs1 >= numSameGIDs2) {
835 tgtMap1HadMaxSameGIDs =
true;
836 numSameIDsUnion = numSameGIDs1;
837 std::copy (sameGIDs1.
begin (), sameGIDs1.
end (), std::back_inserter (unionTgtGIDs));
842 doubleCountedSameGIDs = tgtGIDs1 (numSameGIDs2, numSameGIDs1 - numSameGIDs2);
844 tgtMap1HadMaxSameGIDs =
false;
845 numSameIDsUnion = numSameGIDs2;
846 std::copy (sameGIDs2.
begin (), sameGIDs2.
end (), std::back_inserter (unionTgtGIDs));
851 doubleCountedSameGIDs = tgtGIDs2 (numSameGIDs1, numSameGIDs2 - numSameGIDs1);
854 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 856 std::ostringstream os;
857 os << myRank <<
": union Map's same GIDs: " <<
toString (unionTgtGIDs ()) << endl;
858 os << myRank <<
": doubleCountedSameGIDs: " <<
toString (doubleCountedSameGIDs) << endl;
867 cerr << myRank <<
": Computing permute IDs" << endl;
868 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 876 LO curTgtLid = as<LO> (numSameIDsUnion);
884 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 885 cerr << myRank <<
": Converting permute-to LIDs to GIDs" << endl;
886 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 891 for (size_type k = 0; k < numPermuteIDs1; ++k) {
895 for (size_type k = 0; k < numPermuteIDs2; ++k) {
899 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 901 std::ostringstream os;
902 os << myRank <<
": permuteGIDs1: " <<
toString (permuteGIDs1) << endl;
903 os << myRank <<
": permuteGIDs2: " <<
toString (permuteGIDs2) << endl;
906 cerr << myRank <<
": Sorting and merging permute GID lists" << endl;
907 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 912 std::sort (permuteGIDs1.
begin (), permuteGIDs1.
end ());
913 std::sort (permuteGIDs2.
begin (), permuteGIDs2.
end ());
919 if (tgtMap1HadMaxSameGIDs) {
922 std::set_intersection (permuteGIDs2_beg,
924 doubleCountedSameGIDs.
begin (),
925 doubleCountedSameGIDs.
end (),
930 std::set_intersection (permuteGIDs1_beg,
932 doubleCountedSameGIDs.
begin (),
933 doubleCountedSameGIDs.
end (),
936 std::set_union (permuteGIDs1_beg, permuteGIDs1_end,
937 permuteGIDs2_beg, permuteGIDs2_end,
938 std::back_inserter (unionTgtGIDs));
939 const size_type numPermuteIDsUnion =
940 unionTgtGIDs.
size () - numSameIDsUnion;
942 unionTgtGIDs (numSameIDsUnion, numPermuteIDsUnion).getConst ();
944 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 946 std::ostringstream os;
947 os << myRank <<
": permuteGIDsUnion: " <<
toString (permuteGIDsUnion) << endl;
950 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 952 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 954 cerr << myRank <<
": Computing permute-to LIDs" << endl;
955 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 958 permuteToLIDsUnion.
resize (numPermuteIDsUnion);
959 for (size_type k = 0; k < numPermuteIDsUnion; ++k) {
960 permuteToLIDsUnion[k] = curTgtLid++;
963 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 965 std::ostringstream os;
966 os << myRank <<
": permuteToLIDsUnion: " <<
toString (permuteToLIDsUnion) << endl;
969 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 971 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 973 cerr << myRank <<
": Computing permute-from LIDs" << endl;
974 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 977 permuteFromLIDsUnion.
resize (numPermuteIDsUnion);
978 for (size_type k = 0; k < numPermuteIDsUnion; ++k) {
979 permuteFromLIDsUnion[k] = srcMap->
getLocalElement (permuteGIDsUnion[k]);
982 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 984 std::ostringstream os;
985 os << myRank <<
": permuteFromLIDsUnion: " <<
toString (permuteFromLIDsUnion) << endl;
988 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1010 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1017 cerr << myRank <<
": Computing remote IDs" << endl;
1018 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1023 size_type numRemoteIDsUnion = 0;
1035 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1036 cerr << myRank <<
": Converting remote LIDs to GIDs" << endl;
1037 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1043 for (size_type k = 0; k < remoteLIDs1.
size (); ++k) {
1046 std::sort (remoteGIDs1.begin (), remoteGIDs1.end ());
1048 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1050 std::ostringstream os;
1051 os << myRank <<
": remoteGIDs1: " <<
toString (remoteGIDs1 ()) << endl;
1054 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1057 for (size_type k = 0; k < remoteLIDs2.
size (); ++k) {
1060 std::sort (remoteGIDs2.begin (), remoteGIDs2.end ());
1062 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1064 std::ostringstream os;
1065 os << myRank <<
": remoteGIDs2: " <<
toString (remoteGIDs2 ()) << endl;
1068 cerr << myRank <<
": Merging remote GID lists" << endl;
1069 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1073 const size_type oldSize = unionTgtGIDs.
size ();
1074 std::set_union (remoteGIDs1.begin (), remoteGIDs1.end (),
1075 remoteGIDs2.begin (), remoteGIDs2.end (),
1076 std::back_inserter (unionTgtGIDs));
1077 const size_type newSize = unionTgtGIDs.
size ();
1078 numRemoteIDsUnion = newSize - oldSize;
1079 remoteGIDsUnion = unionTgtGIDs (oldSize, numRemoteIDsUnion);
1081 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1083 std::ostringstream os;
1084 os << myRank <<
": remoteGIDsUnion: " <<
toString (remoteGIDsUnion ()) << endl;
1087 cerr << myRank <<
": Looking up remote GIDs' PIDs in the source Map" << endl;
1088 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1091 remotePIDsUnion.
resize (numRemoteIDsUnion);
1095 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1097 std::ostringstream os;
1098 os << myRank <<
": remotePIDsUnion: " <<
toString (remotePIDsUnion ()) << endl;
1101 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1106 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1107 cerr << myRank <<
": Filtering remote GIDs not owned by any process in the source Map" << endl;
1108 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1110 const size_type numInvalidRemote =
1111 std::count_if (remotePIDsUnion.
begin (), remotePIDsUnion.
end (),
1112 std::bind1st (std::equal_to<int> (), -1));
1113 if (numInvalidRemote == numRemoteIDsUnion) {
1115 unionTgtGIDs.
resize (oldSize);
1116 numRemoteIDsUnion = 0;
1120 std::swap (remotePIDsUnion, newRemotePIDsUnion);
1126 size_type numValidRemote = 0;
1127 for (size_type r = 0; r < numRemoteIDsUnion; ++r) {
1129 if (remotePIDsUnion[r] != -1) {
1130 remotePIDsUnion[numValidRemote] = remotePIDsUnion[r];
1131 remoteGIDsUnion[numValidRemote] = remoteGIDsUnion[r];
1136 numValidRemote != numRemoteIDsUnion - numInvalidRemote, std::logic_error,
1137 "Tpetra::Import::setUnion(): After removing invalid remote GIDs and" 1138 " packing the valid remote GIDs, numValidRemote = " << numValidRemote
1139 <<
" != numRemoteIDsUnion - numInvalidRemote = " 1140 << numRemoteIDsUnion - numInvalidRemote
1141 <<
". Please report this bug to the Tpetra developers.");
1143 unionTgtGIDs.
resize (oldSize + numValidRemote);
1144 numRemoteIDsUnion = numValidRemote;
1145 remoteGIDsUnion = unionTgtGIDs (oldSize, numValidRemote);
1146 remotePIDsUnion.
resize (numValidRemote);
1149 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1151 std::ostringstream os;
1152 os << myRank <<
": remoteGIDsUnion after filtering: " <<
toString (remoteGIDsUnion ()) << endl;
1153 os << myRank <<
": remotePIDsUnion after filtering: " <<
toString (remotePIDsUnion ()) << endl;
1156 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1159 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1160 cerr << myRank <<
": Assigning LIDs (in union target Map) to remote IDs" << endl;
1161 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1166 remoteLIDsUnion.
resize (numRemoteIDsUnion);
1167 for (size_type k = 0; k < numRemoteIDsUnion; ++k) {
1168 remoteLIDsUnion[k] = curTgtLid++;
1171 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1173 std::ostringstream os;
1174 os << myRank <<
": remoteLIDsUnion: " <<
toString (remoteLIDsUnion ()) << endl;
1177 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1179 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1180 cerr << myRank <<
": Sorting remote PIDs, GIDs, and LIDs jointly by PID" << endl;
1181 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1184 remoteGIDsUnion.
begin (), remoteLIDsUnion.
begin ());
1186 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1188 std::ostringstream os;
1189 os << myRank <<
": remoteGIDsUnion sorted: " <<
toString (remoteGIDsUnion ()) << endl;
1190 os << myRank <<
": remotePIDsUnion sorted: " <<
toString (remotePIDsUnion ()) << endl;
1191 os << myRank <<
": remoteLIDsUnion sorted: " <<
toString (remoteLIDsUnion ()) << endl;
1194 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1197 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1199 std::ostringstream os;
1200 os << myRank <<
": unionTgtGIDs after remotes: " 1201 <<
toString (unionTgtGIDs ()) << endl;
1204 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1211 const GO indexBaseUnion =
1214 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1215 cerr << myRank <<
"Creating union target Map" << endl;
1216 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1225 rcp (
new map_type (INVALID, unionTgtGIDs (), indexBaseUnion,
1228 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1235 cerr << myRank <<
": Computing export IDs and Distributor" << endl;
1236 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1251 #ifdef TPETRA_IMPORT_SETUNION_USE_CREATE_FROM_SENDS 1275 sort2 (exportLIDs1Copy.begin (), exportLIDs1Copy.end (),
1276 exportPIDs1Copy.begin ());
1279 merge2 (exportLIDs1_end, exportPIDs1_end,
1280 exportLIDs1Copy.
begin (), exportLIDs1_end,
1281 exportPIDs1Copy.
begin (), exportPIDs1_end,
1286 sort2 (exportLIDs2Copy.begin (), exportLIDs2Copy.end (),
1287 exportPIDs2Copy.begin ());
1290 merge2 (exportLIDs2_end, exportPIDs2_end,
1291 exportLIDs2Copy.
begin (), exportLIDs2_end,
1292 exportPIDs2Copy.
begin (), exportPIDs2_end,
1299 keyValueMerge (exportLIDs1Copy.begin (), exportLIDs1Copy.end (),
1300 exportPIDs1Copy.begin (), exportPIDs1Copy.end (),
1301 exportLIDs2Copy.begin (), exportLIDs2Copy.end (),
1302 exportPIDs2Copy.begin (), exportPIDs2Copy.end (),
1303 std::back_inserter (exportLIDsUnion),
1304 std::back_inserter (exportPIDsUnion),
1309 exportLIDsUnion.
begin ());
1315 #else // NOT TPETRA_IMPORT_SETUNION_USE_CREATE_FROM_SENDS 1323 remotePIDsUnion ().getConst (),
1324 exportGIDsUnion, exportPIDsUnion);
1327 const size_type numExportIDsUnion = exportGIDsUnion.
size ();
1328 exportLIDsUnion.
resize (numExportIDsUnion);
1329 for (size_type k = 0; k < numExportIDsUnion; ++k) {
1332 #endif // TPETRA_IMPORT_SETUNION_USE_CREATE_FROM_SENDS 1334 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1336 std::ostringstream os;
1337 os << myRank <<
": exportGIDsUnion: " <<
toString (exportGIDsUnion ()) << endl;
1338 os << myRank <<
": exportPIDsUnion: " <<
toString (exportPIDsUnion ()) << endl;
1339 os << myRank <<
": exportLIDsUnion: " <<
toString (exportLIDsUnion ()) << endl;
1343 cerr <<
"Creating union Import" << endl;
1344 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1348 rcp (
new import_type (srcMap, unionTgtMap,
1349 as<size_t> (numSameIDsUnion),
1350 permuteToLIDsUnion, permuteFromLIDsUnion,
1351 remoteLIDsUnion, exportLIDsUnion,
1352 exportPIDsUnion, distributor, this->out_));
1353 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1355 cerr <<
"Created union Import; done!" << endl;
1356 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1369 #define TPETRA_IMPORT_INSTANT(LO, GO, NODE) \ 1371 template class Import< LO , GO , NODE >; 1373 #endif // TPETRA_IMPORT_DEF_HPP Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void reserve(size_type n)
ArrayView< const int > getExportPIDs() const
List of processes to which entries will be sent.
ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getTargetMap() const
The Target Map used to construct this Import object.
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
void sort3(const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT3 &first3)
Sort the first array, and apply the same permutation to the second and third arrays.
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
GlobalOrdinal getIndexBase() const
The index base for this Map.
size_t getNumExportIDs() const
Number of entries that must be sent by the calling process to other processes.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
void pushTab(const int tabs=1)
size_t global_size_t
Global size_t object.
void merge2(IT1 &indResultOut, IT2 &valResultOut, IT1 indBeg, IT1 indEnd, IT2 valBeg, IT2 valEnd)
Merge values in place, additively, with the same index.
Import(const Teuchos::RCP< const map_type > &source, const Teuchos::RCP< const map_type > &target)
Construct an Import from the source and target Maps.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void keyValueMerge(KeyInputIterType keyBeg1, KeyInputIterType keyEnd1, ValueInputIterType valBeg1, ValueInputIterType valEnd1, KeyInputIterType keyBeg2, KeyInputIterType keyEnd2, ValueInputIterType valBeg2, ValueInputIterType valEnd2, KeyOutputIterType keyOut, ValueOutputIterType valOut, BinaryFunction f)
Merge two sorted (by keys) sequences of unique (key,value) pairs by combining pairs with equal keys...
ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
#define TPETRA_ABUSE_WARNING(throw_exception_test, Exception, msg)
Handle an abuse warning, according to HAVE_TPETRA_THROW_ABUSE_WARNINGS and HAVE_TPETRA_PRINT_ABUSE_WA...
Import< LocalOrdinal, GlobalOrdinal, Node > & operator=(const Import< LocalOrdinal, GlobalOrdinal, Node > &Source)
Assignment operator.
Implementation detail of Import and Export.
Sets up and executes a communication plan for a Tpetra DistObject.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
size_t createFromSends(const ArrayView< const int > &exportNodeIDs)
Set up Distributor using list of process ranks to which this process will send.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
void resize(size_type new_size, const value_type &x=value_type())
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
std::vector< T >::const_iterator const_iterator
ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
void push_back(const value_type &x)
void sort2(const IT1 &first1, const IT1 &last1, const IT2 &first2)
Sort the first array, and apply the resulting permutation to the second array.
Describes a parallel distribution of objects over processes.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
TypeTo as(const TypeFrom &t)
Stand-alone utility functions and macros.
size_t getNumPermuteIDs() const
Number of IDs to permute but not to communicate.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getSourceMap() const
The Source Map used to construct this Import object.
size_t getNumSameIDs() const
Number of initial identical IDs.
Distributor & getDistributor() const
The Distributor that this Import object uses to move data.
virtual void print(std::ostream &os) const
Print the Import's data to the given output stream.
void assign(size_type n, const value_type &val)
size_t getNumRemoteIDs() const
Number of entries not on the calling process.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream.
std::vector< T >::iterator iterator
const Teuchos::RCP< Node > & getNode() const
Get this Map's Node object.
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.
ArrayView< const T > getConst() const
Binary function that returns its first argument.
std::string toString(const T &t)
Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > setUnion(const Import< LocalOrdinal, GlobalOrdinal, Node > &rhs) const
Return the union of this Import and rhs.