42 #ifndef TPETRA_IMPORT_DEF_HPP 43 #define TPETRA_IMPORT_DEF_HPP 45 #include <Tpetra_Import_decl.hpp> 46 #include <Tpetra_Distributor.hpp> 47 #include <Tpetra_Map.hpp> 48 #include <Tpetra_ImportExportData.hpp> 51 #include <Tpetra_Export.hpp> 52 #include <Teuchos_as.hpp> 57 const bool tpetraImportDebugDefault =
false;
62 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 bool debug = tpetraImportDebugDefault;
68 if (! plist.is_null ()) {
70 debug = plist->get<
bool> (
"Debug");
71 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
74 ImportData_->distributor_.setParameterList (plist);
77 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
80 init (
const Teuchos::RCP<const map_type>& source,
81 const Teuchos::RCP<const map_type>& target,
83 Teuchos::Array<int> & remotePIDs,
84 const Teuchos::RCP<Teuchos::ParameterList>& plist)
94 bool debug = tpetraImportDebugDefault;
95 if (! plist.is_null ()) {
97 debug = plist->get<
bool> (
"Debug");
98 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
102 if (! out_.is_null ()) {
106 std::ostringstream os;
107 const int myRank = source->getComm ()->getRank ();
108 os << myRank <<
": Import ctor" << endl;
111 ImportData_ = rcp (
new data_type (source, target, out_, plist));
113 Array<GlobalOrdinal> remoteGIDs;
114 setupSamePermuteRemote (remoteGIDs);
116 std::ostringstream os;
117 const int myRank = source->getComm ()->getRank ();
118 os << myRank <<
": Import ctor: " 119 <<
"setupSamePermuteRemote done" << endl;
122 if (source->isDistributed ()) {
123 setupExport (remoteGIDs,useRemotePIDs,remotePIDs);
126 std::ostringstream os;
127 const int myRank = source->getComm ()->getRank ();
128 os << myRank <<
": Import ctor: done" << endl;
131 if (! out_.is_null ()) {
136 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 Import (
const Teuchos::RCP<const map_type >& source,
139 const Teuchos::RCP<const map_type >& target) :
140 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
141 debug_ (tpetraImportDebugDefault)
143 Teuchos::Array<int> dummy;
144 init (source, target,
false, dummy, Teuchos::null);
147 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
149 Import (
const Teuchos::RCP<const map_type >& source,
150 const Teuchos::RCP<const map_type >& target,
151 const Teuchos::RCP<Teuchos::FancyOStream>& out) :
153 debug_ (tpetraImportDebugDefault)
155 Teuchos::Array<int> dummy;
156 init (source, target,
false, dummy, Teuchos::null);
159 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
161 Import (
const Teuchos::RCP<const map_type >& source,
162 const Teuchos::RCP<const map_type >& target,
163 const Teuchos::RCP<Teuchos::ParameterList>& plist) :
164 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
165 debug_ (tpetraImportDebugDefault)
167 Teuchos::Array<int> dummy;
168 init (source, target,
false, dummy, plist);
171 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
173 Import (
const Teuchos::RCP<const map_type >& source,
174 const Teuchos::RCP<const map_type >& target,
175 const Teuchos::RCP<Teuchos::FancyOStream>& out,
176 const Teuchos::RCP<Teuchos::ParameterList>& plist) :
178 debug_ (tpetraImportDebugDefault)
180 Teuchos::Array<int> dummy;
181 init (source, target,
false, dummy, plist);
184 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186 Import (
const Teuchos::RCP<const map_type >& source,
187 const Teuchos::RCP<const map_type >& target,
188 Teuchos::Array<int> & remotePIDs) :
189 debug_ (tpetraImportDebugDefault)
191 init (source, target,
true, remotePIDs, Teuchos::null);
195 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
198 : ImportData_ (rhs.ImportData_)
200 , debug_ (rhs.debug_)
203 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
206 : out_ (exporter.out_)
207 , debug_ (exporter.debug_)
209 if (! exporter.ExportData_.is_null ()) {
210 ImportData_ = exporter.ExportData_->reverseClone ();
216 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
220 Teuchos::Array<int>& userRemotePIDs,
221 Teuchos::Array<GlobalOrdinal>& remoteGIDs,
222 const Teuchos::ArrayView<const LocalOrdinal> & userExportLIDs,
223 const Teuchos::ArrayView<const int> & userExportPIDs,
224 const bool useRemotePIDGID,
225 const Teuchos::RCP<Teuchos::ParameterList>& plist,
226 const Teuchos::RCP<Teuchos::FancyOStream>& out) :
227 out_ (out.is_null () ?
231 using Teuchos::Array;
232 using Teuchos::ArrayRCP;
233 using Teuchos::ArrayView;
237 typedef LocalOrdinal LO;
238 typedef GlobalOrdinal GO;
239 typedef Teuchos::Array<int>::size_type size_type;
244 ArrayView<const GO> sourceGIDs = source->getNodeElementList ();
245 ArrayView<const GO> targetGIDs = target->getNodeElementList ();
246 const size_type numSrcGids = sourceGIDs.size ();
247 const size_type numTgtGids = targetGIDs.size ();
248 const size_type numGids = std::min (numSrcGids, numTgtGids);
250 size_type numSameGids = 0;
251 for ( ; numSameGids < numGids && sourceGIDs[numSameGids] == targetGIDs[numSameGids]; ++numSameGids)
255 bool debug = tpetraImportDebugDefault;
256 if (! plist.is_null ()) {
258 debug = plist->get<
bool> (
"Debug");
259 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
263 if (debug_ && ! out_.is_null ()) {
264 std::ostringstream os;
265 const int myRank = source->getComm ()->getRank ();
266 os << myRank <<
": constructExpert " << std::endl;
269 ImportData_ = rcp (
new data_type (source, target, out_, plist));
270 ImportData_->numSameIDs_ = numSameGids;
272 Array<LO>& permuteToLIDs = ImportData_->permuteToLIDs_;
273 Array<LO>& permuteFromLIDs = ImportData_->permuteFromLIDs_;
274 Array<LO>& remoteLIDs = ImportData_->remoteLIDs_;
275 const LO LINVALID = Teuchos::OrdinalTraits<LO>::invalid ();
276 const LO numTgtLids = as<LO> (numTgtGids);
278 if(!useRemotePIDGID) {
283 for (LO tgtLid = numSameGids; tgtLid < numTgtLids; ++tgtLid) {
284 const GO curTargetGid = targetGIDs[tgtLid];
286 const LO srcLid = source->getLocalElement (curTargetGid);
287 if (srcLid != LINVALID) {
288 permuteToLIDs.push_back (tgtLid);
289 permuteFromLIDs.push_back (srcLid);
291 if(!useRemotePIDGID) {
292 remoteGIDs.push_back (curTargetGid);
293 remoteLIDs.push_back (tgtLid);
301 "::constructExpert(): Target has remote LIDs but Source is not " 302 "distributed globally." << std::endl
303 <<
"Importing to a submap of the target map.");
305 Array<int> remotePIDs;
306 remotePIDs.resize (remoteGIDs.size (),0);
309 ArrayView<GO> remoteGIDsView = remoteGIDs ();
310 lookup = source->getRemoteIndexList (remoteGIDsView, remotePIDs ());
311 remoteGIDsView = remoteGIDs ();
313 Array<int>& remoteProcIDs = (useRemotePIDGID) ? userRemotePIDs : remotePIDs;
315 TEUCHOS_TEST_FOR_EXCEPTION( lookup ==
IDNotPresent, std::runtime_error,
316 "Import::Import createExpert: the source Map wasn't able to figure out which process " 317 "owns one or more of the GIDs in the list of remote GIDs. This probably " 318 "means that there is at least one GID owned by some process in the target" 319 " Map which is not owned by any process in the source Map. (That is, the" 320 " source and target Maps do not contain the same set of GIDs globally.)");
327 TEUCHOS_TEST_FOR_EXCEPTION( !(remoteProcIDs.size() == remoteGIDsView.size() &&remoteGIDsView.size() == remoteLIDs.size()), std::runtime_error,
328 "Import::Import createExpert version: Size miss match on RemoteProcIDs, remoteGIDsView and remoteLIDs Array's to sort3. This will produce produce an error, aborting ");
330 sort3 (remoteProcIDs.begin (),
331 remoteProcIDs.end (),
332 remoteGIDsView.begin (),
333 remoteLIDs.begin ());
335 ImportData_->remoteLIDs_ = remoteLIDs;
336 ImportData_->distributor_ =
Distributor (source->getComm(),this->out_);
337 ImportData_->exportPIDs_ = Teuchos::Array<int>(userExportPIDs.size(),0);
338 ImportData_->exportLIDs_ = Teuchos::Array<int>(userExportPIDs.size(),0);
340 bool locallyComplete =
true;
341 for(size_type i=0; i<userExportPIDs.size(); i++) {
342 if (userExportPIDs[i] == -1) {
343 locallyComplete =
false;
345 ImportData_->exportPIDs_[i] = userExportPIDs[i];
346 ImportData_->exportLIDs_[i] = userExportLIDs[i];
348 ImportData_->isLocallyComplete_ = locallyComplete;
350 ImportData_->distributor_.createFromSendsAndRecvs(ImportData_->exportPIDs_,remoteProcIDs);
355 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
357 Import (
const Teuchos::RCP<const map_type>& source,
358 const Teuchos::RCP<const map_type>& target,
359 const size_t numSameIDs,
360 Teuchos::Array<LocalOrdinal>& permuteToLIDs,
361 Teuchos::Array<LocalOrdinal>& permuteFromLIDs,
362 Teuchos::Array<LocalOrdinal>& remoteLIDs,
363 Teuchos::Array<LocalOrdinal>& exportLIDs,
364 Teuchos::Array<int>& exportPIDs,
366 const Teuchos::RCP<Teuchos::FancyOStream>& out,
367 const Teuchos::RCP<Teuchos::ParameterList>& plist) :
368 out_ (out.is_null () ?
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr)) : out),
369 debug_ (tpetraImportDebugDefault)
379 bool debug = tpetraImportDebugDefault;
380 if (! plist.is_null ()) {
382 debug = plist->get<
bool> (
"Debug");
383 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
387 if (! out_.is_null ()) {
390 if (debug_ && ! out_.is_null ()) {
391 std::ostringstream os;
392 const int myRank = source->getComm ()->getRank ();
393 os << myRank <<
": Import expert ctor" << endl;
396 ImportData_ = rcp (
new data_type (source, target, out_, plist));
398 bool locallyComplete =
true;
399 for (Teuchos::Array<int>::size_type i = 0; i < exportPIDs.size (); ++i) {
400 if (exportPIDs[i] == -1) {
401 locallyComplete =
false;
404 ImportData_->isLocallyComplete_ = locallyComplete;
406 ImportData_->numSameIDs_ = numSameIDs;
407 ImportData_->permuteToLIDs_.swap (permuteToLIDs);
408 ImportData_->permuteFromLIDs_.swap (permuteFromLIDs);
409 ImportData_->remoteLIDs_.swap (remoteLIDs);
410 ImportData_->distributor_.swap (distributor);
411 ImportData_->exportLIDs_.swap (exportLIDs);
412 ImportData_->exportPIDs_.swap (exportPIDs);
415 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
419 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
421 return ImportData_->numSameIDs_;
424 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
426 return ImportData_->permuteFromLIDs_.size();
429 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
430 Teuchos::ArrayView<const LocalOrdinal>
432 return ImportData_->permuteFromLIDs_();
435 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
436 Teuchos::ArrayView<const LocalOrdinal>
438 return ImportData_->permuteToLIDs_();
441 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
443 return ImportData_->remoteLIDs_.size();
446 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
447 Teuchos::ArrayView<const LocalOrdinal>
449 return ImportData_->remoteLIDs_();
452 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
454 return ImportData_->exportLIDs_.size();
457 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
458 Teuchos::ArrayView<const LocalOrdinal>
460 return ImportData_->exportLIDs_();
463 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
464 Teuchos::ArrayView<const int>
466 return ImportData_->exportPIDs_();
469 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
470 Teuchos::RCP<const typename Import<LocalOrdinal,GlobalOrdinal,Node>::map_type>
472 return ImportData_->source_;
475 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
476 Teuchos::RCP<const typename Import<LocalOrdinal,GlobalOrdinal,Node>::map_type>
478 return ImportData_->target_;
481 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
484 return ImportData_->distributor_;
487 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
490 return ImportData_->isLocallyComplete_;
493 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
498 ImportData_ = rhs.ImportData_;
503 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
507 const Teuchos::EVerbosityLevel verbLevel)
const 510 this->describeImpl (out,
"Tpetra::Import", verbLevel);
513 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
517 auto out = Teuchos::getFancyOStream (Teuchos::rcpFromRef (os));
519 this->describe (*out, Teuchos::VERB_EXTREME);
522 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
528 using Teuchos::Array;
529 using Teuchos::ArrayRCP;
530 using Teuchos::ArrayView;
533 typedef LocalOrdinal LO;
534 typedef GlobalOrdinal GO;
535 typedef typename ArrayView<const GO>::size_type size_type;
536 const map_type& source = * (getSourceMap ());
537 const map_type& target = * (getTargetMap ());
538 ArrayView<const GO> sourceGIDs = source.getNodeElementList ();
539 ArrayView<const GO> targetGIDs = target.getNodeElementList ();
541 #ifdef HAVE_TPETRA_DEBUG 542 ArrayView<const GO> rawSrcGids = sourceGIDs;
543 ArrayView<const GO> rawTgtGids = targetGIDs;
545 const GO*
const rawSrcGids = sourceGIDs.getRawPtr ();
546 const GO*
const rawTgtGids = targetGIDs.getRawPtr ();
547 #endif // HAVE_TPETRA_DEBUG 548 const size_type numSrcGids = sourceGIDs.size ();
549 const size_type numTgtGids = targetGIDs.size ();
550 const size_type numGids = std::min (numSrcGids, numTgtGids);
558 size_type numSameGids = 0;
559 for ( ; numSameGids < numGids && rawSrcGids[numSameGids] == rawTgtGids[numSameGids]; ++numSameGids)
561 ImportData_->numSameIDs_ = numSameGids;
573 Array<LO>& permuteToLIDs = ImportData_->permuteToLIDs_;
574 Array<LO>& permuteFromLIDs = ImportData_->permuteFromLIDs_;
575 Array<LO>& remoteLIDs = ImportData_->remoteLIDs_;
576 const LO LINVALID = Teuchos::OrdinalTraits<LO>::invalid ();
577 const LO numTgtLids = as<LO> (numTgtGids);
580 for (LO tgtLid = numSameGids; tgtLid < numTgtLids; ++tgtLid) {
581 const GO curTargetGid = rawTgtGids[tgtLid];
584 const LO srcLid = source.getLocalElement (curTargetGid);
585 if (srcLid != LINVALID) {
586 permuteToLIDs.push_back (tgtLid);
587 permuteFromLIDs.push_back (srcLid);
589 remoteGIDs.push_back (curTargetGid);
590 remoteLIDs.push_back (tgtLid);
594 if (remoteLIDs.size () != 0 && ! source.isDistributed ()) {
600 ImportData_->isLocallyComplete_ =
false;
604 (
true, std::runtime_error,
"::setupSamePermuteRemote(): Target has " 605 "remote LIDs but Source is not distributed globally. Importing to a " 606 "submap of the target map.");
611 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
612 void Import<LocalOrdinal,GlobalOrdinal,Node>::
613 setupExport (Teuchos::Array<GlobalOrdinal>& remoteGIDs,
615 Teuchos::Array<int>& userRemotePIDs)
618 using Teuchos::Array;
619 using Teuchos::ArrayRCP;
620 using Teuchos::ArrayView;
623 typedef LocalOrdinal LO;
624 typedef GlobalOrdinal GO;
625 typedef typename Array<int>::difference_type size_type;
626 const char tfecfFuncName[] =
"setupExport: ";
628 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
629 (getSourceMap ().is_null (), std::logic_error,
"Source Map is null. " 630 "Please report this bug to the Tpetra developers.");
631 const map_type& source = * (getSourceMap ());
633 Teuchos::OSTab tab (out_);
642 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
643 (! useRemotePIDs && (userRemotePIDs.size() > 0), std::invalid_argument,
644 "remotePIDs are non-empty but their use has not been requested.");
645 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
646 (userRemotePIDs.size () > 0 && remoteGIDs.size () != userRemotePIDs.size (),
647 std::invalid_argument,
"remotePIDs must either be of size zero or match " 648 "the size of remoteGIDs.");
652 ArrayView<GO> remoteGIDsView = remoteGIDs ();
653 ArrayView<int> remoteProcIDsView;
673 Array<int> newRemotePIDs;
676 if (! useRemotePIDs) {
677 newRemotePIDs.resize (remoteGIDsView.size ());
678 if (debug_ && ! out_.is_null ()) {
679 std::ostringstream os;
680 const int myRank = source.getComm ()->getRank ();
681 os << myRank <<
": Import::setupExport: about to call " 682 "getRemoteIndexList on source Map" << endl;
685 lookup = source.getRemoteIndexList (remoteGIDsView, newRemotePIDs ());
687 Array<int>& remoteProcIDs = useRemotePIDs ? userRemotePIDs : newRemotePIDs;
693 ImportData_->isLocallyComplete_ =
false;
698 (
true, std::runtime_error,
"::setupExport(): the source Map wasn't " 699 "able to figure out which process owns one or more of the GIDs in the " 700 "list of remote GIDs. This probably means that there is at least one " 701 "GID owned by some process in the target Map which is not owned by any" 702 " process in the source Map. (That is, the source and target Maps do " 703 "not contain the same set of GIDs globally.)");
709 const size_type numInvalidRemote =
710 std::count_if (remoteProcIDs.begin (), remoteProcIDs.end (),
711 std::bind1st (std::equal_to<int> (), -1));
712 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
713 (numInvalidRemote == 0, std::logic_error,
"Calling getRemoteIndexList " 714 "on the source Map returned IDNotPresent, but none of the returned " 715 "\"remote\" process ranks are -1. Please report this bug to the " 716 "Tpetra developers.");
719 const size_type totalNumRemote = getNumRemoteIDs ();
720 if (numInvalidRemote == totalNumRemote) {
722 remoteProcIDs.clear ();
724 ImportData_->remoteLIDs_.clear();
729 size_type numValidRemote = 0;
730 #ifdef HAVE_TPETRA_DEBUG 731 ArrayView<GlobalOrdinal> remoteGIDsPtr = remoteGIDsView;
733 GlobalOrdinal*
const remoteGIDsPtr = remoteGIDsView.getRawPtr ();
734 #endif // HAVE_TPETRA_DEBUG 735 for (size_type r = 0; r < totalNumRemote; ++r) {
737 if (remoteProcIDs[r] != -1) {
738 remoteProcIDs[numValidRemote] = remoteProcIDs[r];
739 remoteGIDsPtr[numValidRemote] = remoteGIDsPtr[r];
740 ImportData_->remoteLIDs_[numValidRemote] = ImportData_->remoteLIDs_[r];
744 TEUCHOS_TEST_FOR_EXCEPTION(
745 numValidRemote != totalNumRemote - numInvalidRemote, std::logic_error,
746 "Tpetra::Import::setupExport(): After removing invalid remote GIDs and" 747 " packing the valid remote GIDs, numValidRemote = " << numValidRemote
748 <<
" != totalNumRemote - numInvalidRemote = " 749 << totalNumRemote - numInvalidRemote
750 <<
". Please report this bug to the Tpetra developers.");
752 remoteProcIDs.resize (numValidRemote);
753 remoteGIDs.resize (numValidRemote);
754 ImportData_->remoteLIDs_.resize (numValidRemote);
757 remoteGIDsView = remoteGIDs ();
765 sort3 (remoteProcIDs.begin (),
766 remoteProcIDs.end (),
767 remoteGIDsView.begin (),
768 ImportData_->remoteLIDs_.begin ());
775 Array<GO> exportGIDs;
776 ImportData_->distributor_.createFromRecvs (remoteGIDsView ().getConst (),
777 remoteProcIDs, exportGIDs,
778 ImportData_->exportPIDs_);
794 const size_type numExportIDs = exportGIDs.size ();
795 if (numExportIDs > 0) {
796 ImportData_->exportLIDs_.resize (numExportIDs);
797 ArrayView<const GO> expGIDs = exportGIDs ();
798 ArrayView<LO> expLIDs = ImportData_->exportLIDs_ ();
799 for (size_type k = 0; k < numExportIDs; ++k) {
800 expLIDs[k] = source.getLocalElement (expGIDs[k]);
804 if (debug_ && ! out_.is_null ()) {
805 std::ostringstream os;
806 const int myRank = source.getComm ()->getRank ();
807 os << myRank <<
": Import::setupExport: done" << endl;
813 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
814 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
819 using Teuchos::Array;
820 using Teuchos::ArrayView;
825 using Teuchos::outArg;
826 using Teuchos::REDUCE_MIN;
827 using Teuchos::reduceAll;
828 typedef LocalOrdinal LO;
829 typedef GlobalOrdinal GO;
831 typedef typename Array<GO>::size_type size_type;
833 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 834 using Teuchos::toString;
837 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 839 RCP<const map_type> srcMap = this->getSourceMap ();
840 RCP<const map_type> tgtMap1 = this->getTargetMap ();
842 RCP<const Comm<int> > comm = srcMap->getComm ();
844 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 845 const int myRank = comm->getRank ();
846 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 848 #ifdef HAVE_TPETRA_DEBUG 849 TEUCHOS_TEST_FOR_EXCEPTION(
850 ! srcMap->isSameAs (* (rhs.
getSourceMap ())), std::invalid_argument,
851 "Tpetra::Import::setUnion: The source Map of the input Import must be the " 852 "same as (in the sense of Map::isSameAs) the source Map of this Import.");
853 TEUCHOS_TEST_FOR_EXCEPTION(
855 std::invalid_argument,
"Tpetra::Import::setUnion: " 856 "The target Maps must have congruent communicators.");
857 #endif // HAVE_TPETRA_DEBUG 862 if (tgtMap1->isSameAs (*tgtMap2)) {
863 return rcp (
new import_type (*
this));
868 ArrayView<const GO> srcGIDs = srcMap->getNodeElementList ();
869 ArrayView<const GO> tgtGIDs1 = tgtMap1->getNodeElementList ();
870 ArrayView<const GO> tgtGIDs2 = tgtMap2->getNodeElementList ();
872 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 875 std::ostringstream os;
876 os << myRank <<
": srcGIDs: " << toString (srcGIDs) << endl;
877 os << myRank <<
": tgtGIDs1: " << toString (tgtGIDs1) << endl;
878 os << myRank <<
": tgtGIDs2: " << toString (tgtGIDs2) << endl;
882 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 887 Array<GO> unionTgtGIDs;
892 unionTgtGIDs.reserve (tgtGIDs1.size () + tgtGIDs2.size ());
894 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 901 cerr << myRank <<
": Computing \"same\" GIDs" << endl;
902 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 908 const size_type numSameGIDs1 = this->getNumSameIDs ();
910 ArrayView<const GO> sameGIDs1 = tgtGIDs1 (0, numSameGIDs1);
911 ArrayView<const GO> sameGIDs2 = tgtGIDs2 (0, numSameGIDs2);
912 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 914 std::ostringstream os;
915 os << myRank <<
": same IDs for target Map 1: " << toString (sameGIDs1) << endl;
916 os << myRank <<
": same IDs for target Map 2: " << toString (sameGIDs2) << endl;
919 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 927 ArrayView<const GO> doubleCountedSameGIDs;
928 size_type numSameIDsUnion;
929 bool tgtMap1HadMaxSameGIDs;
930 if (numSameGIDs1 >= numSameGIDs2) {
931 tgtMap1HadMaxSameGIDs =
true;
932 numSameIDsUnion = numSameGIDs1;
933 std::copy (sameGIDs1.begin (), sameGIDs1.end (), std::back_inserter (unionTgtGIDs));
938 doubleCountedSameGIDs = tgtGIDs1 (numSameGIDs2, numSameGIDs1 - numSameGIDs2);
940 tgtMap1HadMaxSameGIDs =
false;
941 numSameIDsUnion = numSameGIDs2;
942 std::copy (sameGIDs2.begin (), sameGIDs2.end (), std::back_inserter (unionTgtGIDs));
947 doubleCountedSameGIDs = tgtGIDs2 (numSameGIDs1, numSameGIDs2 - numSameGIDs1);
950 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 952 std::ostringstream os;
953 os << myRank <<
": union Map's same GIDs: " << toString (unionTgtGIDs ()) << endl;
954 os << myRank <<
": doubleCountedSameGIDs: " << toString (doubleCountedSameGIDs) << endl;
963 cerr << myRank <<
": Computing permute IDs" << endl;
964 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 970 Array<LO> permuteFromLIDsUnion;
971 Array<LO> permuteToLIDsUnion;
972 LO curTgtLid = as<LO> (numSameIDsUnion);
975 ArrayView<const LO> permuteToLIDs1 = this->getPermuteToLIDs ();
977 const size_type numPermuteIDs1 = this->getNumPermuteIDs ();
980 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 981 cerr << myRank <<
": Converting permute-to LIDs to GIDs" << endl;
982 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 986 Array<GO> permuteGIDs1 (numPermuteIDs1);
987 for (size_type k = 0; k < numPermuteIDs1; ++k) {
988 permuteGIDs1[k] = tgtMap1->getGlobalElement (permuteToLIDs1[k]);
990 Array<GO> permuteGIDs2 (numPermuteIDs2);
991 for (size_type k = 0; k < numPermuteIDs2; ++k) {
992 permuteGIDs2[k] = tgtMap2->getGlobalElement (permuteToLIDs2[k]);
995 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 997 std::ostringstream os;
998 os << myRank <<
": permuteGIDs1: " << toString (permuteGIDs1) << endl;
999 os << myRank <<
": permuteGIDs2: " << toString (permuteGIDs2) << endl;
1002 cerr << myRank <<
": Sorting and merging permute GID lists" << endl;
1003 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1008 std::sort (permuteGIDs1.begin (), permuteGIDs1.end ());
1009 std::sort (permuteGIDs2.begin (), permuteGIDs2.end ());
1011 typename Array<GO>::iterator permuteGIDs1_beg = permuteGIDs1.begin ();
1012 typename Array<GO>::iterator permuteGIDs1_end = permuteGIDs1.end ();
1013 typename Array<GO>::iterator permuteGIDs2_beg = permuteGIDs2.begin ();
1014 typename Array<GO>::iterator permuteGIDs2_end = permuteGIDs2.end ();
1015 if (tgtMap1HadMaxSameGIDs) {
1018 std::set_difference(permuteGIDs2_beg,
1020 doubleCountedSameGIDs.begin (),
1021 doubleCountedSameGIDs.end (),
1028 std::set_difference(permuteGIDs1_beg,
1030 doubleCountedSameGIDs.begin (),
1031 doubleCountedSameGIDs.end (),
1035 std::set_union (permuteGIDs1_beg, permuteGIDs1_end,
1036 permuteGIDs2_beg, permuteGIDs2_end,
1037 std::back_inserter (unionTgtGIDs));
1039 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1041 std::ostringstream os;
1042 if(tgtMap1HadMaxSameGIDs) os << myRank <<
": tgtMap1HadMaxSameGIDs == true"<<endl;
1043 else os << myRank <<
": tgtMap1HadMaxSameGIDs == false"<<endl;
1045 os << myRank <<
": reduced permuteGIDs1: {";
1046 for(
typename Array<GO>::iterator k = permuteGIDs1_beg; k != permuteGIDs1_end; k++)
1049 os << myRank <<
": reduced permuteGIDs2: {";
1050 for(
typename Array<GO>::iterator k = permuteGIDs2_beg; k != permuteGIDs2_end; k++)
1056 const size_type numPermuteIDsUnion =
1057 unionTgtGIDs.size () - numSameIDsUnion;
1058 ArrayView<const GO> permuteGIDsUnion =
1059 unionTgtGIDs (numSameIDsUnion, numPermuteIDsUnion).getConst ();
1061 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1063 std::ostringstream os;
1064 os << myRank <<
": permuteGIDsUnion: " << toString (permuteGIDsUnion) << endl;
1067 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1069 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1071 cerr << myRank <<
": Computing permute-to LIDs" << endl;
1072 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1075 permuteToLIDsUnion.resize (numPermuteIDsUnion);
1076 for (size_type k = 0; k < numPermuteIDsUnion; ++k) {
1077 permuteToLIDsUnion[k] = curTgtLid++;
1080 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1082 std::ostringstream os;
1083 os << myRank <<
": permuteToLIDsUnion: " << toString (permuteToLIDsUnion) << endl;
1086 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1088 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1090 cerr << myRank <<
": Computing permute-from LIDs" << endl;
1091 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1094 permuteFromLIDsUnion.resize (numPermuteIDsUnion);
1095 for (size_type k = 0; k < numPermuteIDsUnion; ++k) {
1096 permuteFromLIDsUnion[k] = srcMap->getLocalElement (permuteGIDsUnion[k]);
1099 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1101 std::ostringstream os;
1102 os << myRank <<
": permuteFromLIDsUnion: " << toString (permuteFromLIDsUnion) << endl;
1105 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1109 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1111 std::ostringstream os;
1112 os << myRank <<
": unionTgtGIDs after permutes: " 1113 << toString (unionTgtGIDs ()) << endl;
1116 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1137 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1144 cerr << myRank <<
": Computing remote IDs" << endl;
1145 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1147 Array<GO> remoteGIDsUnion;
1148 Array<int> remotePIDsUnion;
1149 Array<LO> remoteLIDsUnion;
1150 size_type numRemoteIDsUnion = 0;
1160 ArrayView<const LO> remoteLIDs1 = this->getRemoteLIDs();
1164 Array<int> remotePIDs1, remotePIDs2;
1165 Tpetra::Import_Util::getRemotePIDs(*
this,remotePIDs1);
1166 Tpetra::Import_Util::getRemotePIDs(rhs,remotePIDs2);
1169 Array<std::pair<int,GO> > remotePGIDs1, remotePGIDs2,remotePGUnion;
1170 remotePGIDs1.resize(remotePIDs1.size());
1171 remotePGIDs2.resize(remotePIDs2.size());
1173 for(size_type k=0; k < remotePIDs1.size(); k++)
1174 remotePGIDs1[k] = std::pair<int,GO>(remotePIDs1[k],this->getTargetMap()->getGlobalElement(remoteLIDs1[k]));
1176 for(size_type k=0; k < remotePIDs2.size(); k++)
1177 remotePGIDs2[k] = std::pair<int,GO>(remotePIDs2[k],rhs.
getTargetMap()->getGlobalElement(remoteLIDs2[k]));
1181 std::sort(remotePGIDs1.begin(), remotePGIDs1.end());
1182 std::sort(remotePGIDs2.begin(), remotePGIDs2.end());
1183 std::merge(remotePGIDs1.begin(), remotePGIDs1.end(),
1184 remotePGIDs2.begin(), remotePGIDs2.end(),
1185 std::back_inserter(remotePGUnion));
1186 typename Array<std::pair<int,GO> >::iterator it = std::unique(remotePGUnion.begin(),remotePGUnion.end());
1187 remotePGUnion.resize(std::distance(remotePGUnion.begin(),it));
1190 numRemoteIDsUnion = remotePGUnion.size();
1191 remoteLIDsUnion.resize(numRemoteIDsUnion);
1192 remotePIDsUnion.resize(numRemoteIDsUnion);
1193 remoteGIDsUnion.resize(numRemoteIDsUnion);
1195 for (size_type k = 0; k < numRemoteIDsUnion; ++k) {
1196 remoteLIDsUnion[k] = curTgtLid++;
1197 remotePIDsUnion[k] = remotePGUnion[k].first;
1198 remoteGIDsUnion[k] = remotePGUnion[k].second;
1202 const size_type oldSize = unionTgtGIDs.size();
1203 unionTgtGIDs.resize(oldSize + numRemoteIDsUnion);
1204 for(size_type k=0; k<numRemoteIDsUnion; k++)
1205 unionTgtGIDs[oldSize+k] = remoteGIDsUnion[k];
1207 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1210 Array<GO> remoteGIDs1(remotePIDs1.size());
1211 Array<GO> remoteGIDs2(remotePIDs2.size());
1212 for(size_type k=0; k < remotePIDs1.size(); k++)
1213 remoteGIDs1[k] = this->getTargetMap()->getGlobalElement(remoteLIDs1[k]);
1214 for(size_type k=0; k < remotePIDs2.size(); k++)
1215 remoteGIDs2[k] = rhs.
getTargetMap()->getGlobalElement(remoteLIDs2[k]);
1217 std::ostringstream os;
1218 os << myRank <<
": remoteGIDs1 : " << toString (remoteGIDs1 ()) << endl;
1219 os << myRank <<
": remotePIDs1 : " << toString (remotePIDs1 ()) << endl;
1220 os << myRank <<
": remoteGIDs2 : " << toString (remoteGIDs2 ()) << endl;
1221 os << myRank <<
": remotePIDs2 : " << toString (remotePIDs2 ()) << endl;
1227 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1229 std::ostringstream os;
1230 os << myRank <<
": remoteGIDsUnion sorted: " << toString (remoteGIDsUnion ()) << endl;
1231 os << myRank <<
": remotePIDsUnion sorted: " << toString (remotePIDsUnion ()) << endl;
1232 os << myRank <<
": remoteLIDsUnion sorted: " << toString (remoteLIDsUnion ()) << endl;
1235 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1238 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1240 std::ostringstream os;
1241 os << myRank <<
": unionTgtGIDs after remotes: " 1242 << toString (unionTgtGIDs ()) << endl;
1245 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1252 const GO indexBaseUnion =
1253 std::min (tgtMap1->getIndexBase (), tgtMap2->getIndexBase ());
1255 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1256 cerr << myRank <<
"Creating union target Map" << endl;
1257 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1279 const GST INVALID = Teuchos::OrdinalTraits<GST>::invalid ();
1280 RCP<const map_type> unionTgtMap =
1281 rcp (
new map_type (INVALID, unionTgtGIDs (), indexBaseUnion,
1282 comm, srcMap->getNode ()));
1284 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1291 cerr << myRank <<
": Computing export IDs and Distributor" << endl;
1292 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1302 Array<GO> exportGIDsUnion;
1303 Array<LO> exportLIDsUnion;
1304 Array<int> exportPIDsUnion;
1307 #ifdef TPETRA_IMPORT_SETUNION_USE_CREATE_FROM_SENDS 1315 ArrayView<const LO> exportLIDs1 = this->getExportLIDs ();
1316 ArrayView<const LO> exportPIDs1 = this->getExportPIDs ();
1329 Array<LO> exportLIDs1Copy (exportLIDs1.begin (), exportLIDs1.end ());
1330 Array<int> exportPIDs1Copy (exportLIDs1.begin (), exportLIDs1.end ());
1331 sort2 (exportLIDs1Copy.begin (), exportLIDs1Copy.end (),
1332 exportPIDs1Copy.begin ());
1333 typename ArrayView<LO>::iterator exportLIDs1_end = exportLIDs1Copy.end ();
1334 typename ArrayView<LO>::iterator exportPIDs1_end = exportPIDs1Copy.end ();
1335 merge2 (exportLIDs1_end, exportPIDs1_end,
1336 exportLIDs1Copy.begin (), exportLIDs1_end,
1337 exportPIDs1Copy.begin (), exportPIDs1_end,
1340 Array<LO> exportLIDs2Copy (exportLIDs2.begin (), exportLIDs2.end ());
1341 Array<int> exportPIDs2Copy (exportLIDs2.begin (), exportLIDs2.end ());
1342 sort2 (exportLIDs2Copy.begin (), exportLIDs2Copy.end (),
1343 exportPIDs2Copy.begin ());
1344 typename ArrayView<LO>::iterator exportLIDs2_end = exportLIDs2Copy.end ();
1345 typename ArrayView<LO>::iterator exportPIDs2_end = exportPIDs2Copy.end ();
1346 merge2 (exportLIDs2_end, exportPIDs2_end,
1347 exportLIDs2Copy.begin (), exportLIDs2_end,
1348 exportPIDs2Copy.begin (), exportPIDs2_end,
1355 keyValueMerge (exportLIDs1Copy.begin (), exportLIDs1Copy.end (),
1356 exportPIDs1Copy.begin (), exportPIDs1Copy.end (),
1357 exportLIDs2Copy.begin (), exportLIDs2Copy.end (),
1358 exportPIDs2Copy.begin (), exportPIDs2Copy.end (),
1359 std::back_inserter (exportLIDsUnion),
1360 std::back_inserter (exportPIDsUnion),
1364 sort2 (exportPIDsUnion.begin (), exportPIDsUnion.end (),
1365 exportLIDsUnion.begin ());
1371 #else // NOT TPETRA_IMPORT_SETUNION_USE_CREATE_FROM_SENDS 1379 remotePIDsUnion ().getConst (),
1380 exportGIDsUnion, exportPIDsUnion);
1383 const size_type numExportIDsUnion = exportGIDsUnion.size ();
1384 exportLIDsUnion.resize (numExportIDsUnion);
1385 for (size_type k = 0; k < numExportIDsUnion; ++k) {
1386 exportLIDsUnion[k] = srcMap->getLocalElement (exportGIDsUnion[k]);
1388 #endif // TPETRA_IMPORT_SETUNION_USE_CREATE_FROM_SENDS 1390 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1392 std::ostringstream os;
1393 os << myRank <<
": exportGIDsUnion: " << toString (exportGIDsUnion ()) << endl;
1394 os << myRank <<
": exportPIDsUnion: " << toString (exportPIDsUnion ()) << endl;
1395 os << myRank <<
": exportLIDsUnion: " << toString (exportLIDsUnion ()) << endl;
1399 cerr <<
"Creating union Import" << endl;
1400 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1403 RCP<const import_type> unionImport =
1404 rcp (
new import_type (srcMap, unionTgtMap,
1405 as<size_t> (numSameIDsUnion),
1406 permuteToLIDsUnion, permuteFromLIDsUnion,
1407 remoteLIDsUnion, exportLIDsUnion,
1408 exportPIDsUnion, distributor, this->out_));
1409 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1411 cerr <<
"Created union Import; done!" << endl;
1412 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1419 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1420 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
1424 using Teuchos::Array;
1425 using Teuchos::ArrayView;
1427 using Teuchos::Comm;
1430 using Teuchos::outArg;
1431 using Teuchos::REDUCE_MIN;
1432 using Teuchos::reduceAll;
1433 typedef LocalOrdinal LO;
1434 typedef GlobalOrdinal GO;
1435 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > unionImport;
1436 RCP<const map_type> srcMap = this->getSourceMap ();
1437 RCP<const map_type> tgtMap = this->getTargetMap ();
1438 RCP<const Comm<int> > comm = srcMap->getComm ();
1440 #ifdef HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1441 const int myRank = comm->getRank ();
1442 #endif // HAVE_TPETRA_IMPORT_SETUNION_EXTRA_DEBUG_OUTPUT 1444 ArrayView<const GO> srcGIDs = srcMap->getNodeElementList ();
1445 ArrayView<const GO> tgtGIDs = tgtMap->getNodeElementList ();
1448 size_t numSameIDsNew = srcMap->getNodeNumElements();
1449 size_t numRemoteIDsNew = getNumRemoteIDs();
1450 Array<LO> permuteToLIDsNew, permuteFromLIDsNew;
1453 ArrayView<const LO> remoteLIDsOld = getRemoteLIDs();
1454 ArrayView<const LO> exportLIDsOld = getExportLIDs();
1457 Array<GO> GIDs(numSameIDsNew + numRemoteIDsNew);
1458 for(
size_t i=0; i<numSameIDsNew; i++)
1459 GIDs[i] = srcGIDs[i];
1462 Array<LO> remoteLIDsNew(numRemoteIDsNew);
1463 for(
size_t i=0; i<numRemoteIDsNew; i++) {
1464 GIDs[numSameIDsNew + i] = tgtGIDs[remoteLIDsOld[i]];
1465 remoteLIDsNew[i] = numSameIDsNew+i;
1469 GO GO_INVALID = Teuchos::OrdinalTraits<GO>::invalid();
1470 RCP<const map_type> targetMapNew = rcp(
new map_type(GO_INVALID,GIDs,tgtMap->getIndexBase(),tgtMap->getComm(),tgtMap->getNode()));
1473 Array<int> exportPIDsnew(getExportPIDs());
1474 Array<LO> exportLIDsnew(getExportLIDs());
1495 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1496 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
1503 const size_t NumRemotes = getNumRemoteIDs ();
1504 TEUCHOS_TEST_FOR_EXCEPTION(
1505 NumRemotes != remoteTarget->getNodeNumElements (),
1506 std::runtime_error,
"Tpetra::createRemoteOnlyImport: " 1507 "remoteTarget map ID count doesn't match.");
1510 Teuchos::ArrayView<const LocalOrdinal> oldRemoteLIDs = getRemoteLIDs ();
1511 Teuchos::Array<LocalOrdinal> newRemoteLIDs (NumRemotes);
1512 for (
size_t i = 0; i < NumRemotes; ++i) {
1513 newRemoteLIDs[i] = remoteTarget->getLocalElement (getTargetMap ()->getGlobalElement (oldRemoteLIDs[i]));
1515 TEUCHOS_TEST_FOR_EXCEPTION(
1516 i > 0 && newRemoteLIDs[i] < newRemoteLIDs[i-1],
1517 std::runtime_error,
"Tpetra::createRemoteOnlyImport: " 1518 "this and remoteTarget order don't match.");
1526 Teuchos::Array<int> newExportPIDs (getExportPIDs ());
1527 Teuchos::Array<LocalOrdinal> newExportLIDs (getExportLIDs ());
1528 Teuchos::Array<LocalOrdinal> dummy;
1531 return rcp (
new import_type (getSourceMap (), remoteTarget,
1532 static_cast<size_t> (0), dummy, dummy,
1533 newRemoteLIDs, newExportLIDs,
1534 newExportPIDs, newDistor));
1539 #define TPETRA_IMPORT_CLASS_INSTANT(LO, GO, NODE) \ 1541 template class Import< LO , GO , NODE >; 1550 #define TPETRA_IMPORT_INSTANT(LO, GO, NODE) \ 1551 TPETRA_IMPORT_CLASS_INSTANT(LO, GO, NODE) 1553 #endif // TPETRA_IMPORT_DEF_HPP bool congruent(const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
Whether the two communicators are congruent.
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.
Teuchos::ArrayView< const int > getExportPIDs() const
List of processes to which entries will be sent.
Teuchos::ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
Teuchos::RCP< const map_type > getSourceMap() const
The Source Map used to construct this Import object.
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.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
Teuchos::ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
virtual ~Import()
Destructor.
Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > setUnion() const
Return the union of this Import this->getSourceMap()
bool isLocallyComplete() const
Do all target Map indices on the calling process exist on at least one process (not necessarily this ...
size_t createFromSends(const Teuchos::ArrayView< const int > &exportProcIDs)
Set up Distributor using list of process ranks to which this process will send.
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::ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
size_t getNumPermuteIDs() const
Number of IDs to permute but not to communicate.
Teuchos::ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
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...
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Teuchos::RCP< const map_type > getTargetMap() const
The Target Map used to construct this Import object.
#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.
size_t getNumRemoteIDs() const
Number of entries not on the calling process.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set parameters.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object in a human-readable way to the given output stream.
size_t getNumExportIDs() const
Number of entries that must be sent by the calling process to other processes.
virtual void print(std::ostream &os) const
Print the Import's data to the given output stream.
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.
Internal functions and macros designed for use with Tpetra::Import and Tpetra::Export objects...
Stand-alone utility functions and macros.
size_t getNumSameIDs() const
Number of initial identical IDs.
Distributor & getDistributor() const
The Distributor that this Import object uses to move data.
Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > createRemoteOnlyImport(const Teuchos::RCP< const map_type > &remoteTarget) const
Returns an importer that contains only the remote entries of this.
void createFromRecvs(const Teuchos::ArrayView< const Ordinal > &remoteIDs, const Teuchos::ArrayView< const int > &remoteProcIDs, Teuchos::Array< Ordinal > &exportIDs, Teuchos::Array< int > &exportProcIDs)
Set up Distributor using list of process ranks from which to receive.
Binary function that returns its first argument.