42 #ifndef TPETRA_EXPORT_DEF_HPP 43 #define TPETRA_EXPORT_DEF_HPP 45 #include <Tpetra_Export_decl.hpp> 47 #include <Tpetra_Distributor.hpp> 48 #include <Tpetra_Map.hpp> 49 #include <Tpetra_ImportExportData.hpp> 51 #include <Tpetra_Import.hpp> 52 #include <Teuchos_as.hpp> 56 const bool tpetraExportDebugDefault =
false;
60 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 bool debug = tpetraExportDebugDefault;
66 if (! plist.is_null ()) {
68 debug = plist->get<
bool> (
"Debug");
69 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
72 ExportData_->distributor_.setParameterList (plist);
75 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 Export (
const Teuchos::RCP<const map_type >& source,
78 const Teuchos::RCP<const map_type >& target) :
80 debug_ (tpetraExportDebugDefault)
86 if (! out_.is_null ()) {
90 std::ostringstream os;
91 const int myRank = source->getComm ()->getRank ();
92 os << myRank <<
": Export ctor" << endl;
95 ExportData_ = rcp (
new data_type (source, target, out_));
96 Teuchos::Array<GlobalOrdinal> exportGIDs;
97 setupSamePermuteExport (exportGIDs);
99 std::ostringstream os;
100 const int myRank = source->getComm ()->getRank ();
101 os << myRank <<
": Export ctor: " 102 <<
"setupSamePermuteExport done" << endl;
105 if (source->isDistributed ()) {
106 setupRemote (exportGIDs);
109 std::ostringstream os;
110 const int myRank = source->getComm ()->getRank ();
111 os << myRank <<
": Export ctor: done" << endl;
114 if (! out_.is_null ()) {
119 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
121 Export (
const Teuchos::RCP<const map_type >& source,
122 const Teuchos::RCP<const map_type >& target,
123 const Teuchos::RCP<Teuchos::FancyOStream>& out) :
125 debug_ (tpetraExportDebugDefault)
131 if (! out_.is_null ()) {
135 std::ostringstream os;
136 const int myRank = source->getComm ()->getRank ();
137 os << myRank <<
": Export ctor" << endl;
140 ExportData_ = rcp (
new data_type (source, target, out));
141 Teuchos::Array<GlobalOrdinal> exportGIDs;
142 setupSamePermuteExport (exportGIDs);
144 std::ostringstream os;
145 const int myRank = source->getComm ()->getRank ();
146 os << myRank <<
": Export ctor: " 147 <<
"setupSamePermuteExport done" << endl;
150 if (source->isDistributed ()) {
151 setupRemote (exportGIDs);
154 std::ostringstream os;
155 const int myRank = source->getComm ()->getRank ();
156 os << myRank <<
": Export ctor: done" << endl;
159 if (! out_.is_null ()) {
164 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
166 Export (
const Teuchos::RCP<const map_type >& source,
167 const Teuchos::RCP<const map_type >& target,
168 const Teuchos::RCP<Teuchos::ParameterList>& plist) :
169 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
170 debug_ (tpetraExportDebugDefault)
177 bool debug = tpetraExportDebugDefault;
178 if (! plist.is_null ()) {
180 debug = plist->get<
bool> (
"Debug");
181 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
185 if (! out_.is_null ()) {
189 std::ostringstream os;
190 const int myRank = source->getComm ()->getRank ();
191 os << myRank <<
": Export ctor" << endl;
194 ExportData_ = rcp (
new data_type (source, target, out_, plist));
195 Teuchos::Array<GlobalOrdinal> exportGIDs;
196 setupSamePermuteExport (exportGIDs);
198 std::ostringstream os;
199 const int myRank = source->getComm ()->getRank ();
200 os << myRank <<
": Export ctor: " 201 <<
"setupSamePermuteExport done" << endl;
204 if (source->isDistributed ()) {
205 setupRemote (exportGIDs);
208 std::ostringstream os;
209 const int myRank = source->getComm ()->getRank ();
210 os << myRank <<
": Export ctor: done" << endl;
213 if (! out_.is_null ()) {
218 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
220 Export (
const Teuchos::RCP<const map_type >& source,
221 const Teuchos::RCP<const map_type >& target,
222 const Teuchos::RCP<Teuchos::FancyOStream>& out,
223 const Teuchos::RCP<Teuchos::ParameterList>& plist) :
224 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
225 debug_ (tpetraExportDebugDefault)
232 bool debug = tpetraExportDebugDefault;
233 if (! plist.is_null ()) {
235 debug = plist->get<
bool> (
"Debug");
236 }
catch (Teuchos::Exceptions::InvalidParameter&) {}
240 if (! out_.is_null ()) {
244 std::ostringstream os;
245 const int myRank = source->getComm ()->getRank ();
246 os << myRank <<
": Export ctor" << endl;
249 ExportData_ = rcp (
new data_type (source, target, out, plist));
250 Teuchos::Array<GlobalOrdinal> exportGIDs;
251 setupSamePermuteExport (exportGIDs);
253 std::ostringstream os;
254 const int myRank = source->getComm ()->getRank ();
255 os << myRank <<
": Export ctor: " 256 <<
"setupSamePermuteExport done" << endl;
259 if (source->isDistributed ()) {
260 setupRemote (exportGIDs);
263 std::ostringstream os;
264 const int myRank = source->getComm ()->getRank ();
265 os << myRank <<
": Export ctor: done" << endl;
268 if (! out_.is_null ()) {
273 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
276 : ExportData_ (rhs.ExportData_),
282 if (! out_.is_null ()) {
286 std::ostringstream os;
287 const int myRank =
getSourceMap ()->getComm ()->getRank ();
288 os << myRank <<
": Export copy ctor (done)" << endl;
291 if (! out_.is_null ()) {
296 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
299 : out_ (importer.out_)
300 , debug_ (importer.debug_)
302 if(!importer.ImportData_.is_null()) ExportData_ = importer.ImportData_->reverseClone();
305 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
309 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 return ExportData_->numSameIDs_;
314 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
316 return ExportData_->permuteFromLIDs_.size();
319 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
320 Teuchos::ArrayView<const LocalOrdinal>
322 return ExportData_->permuteFromLIDs_();
325 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
326 Teuchos::ArrayView<const LocalOrdinal>
328 return ExportData_->permuteToLIDs_();
331 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
333 return ExportData_->remoteLIDs_.size();
336 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
337 Teuchos::ArrayView<const LocalOrdinal>
339 return ExportData_->remoteLIDs_();
342 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
344 return ExportData_->exportLIDs_.size();
347 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
348 Teuchos::ArrayView<const LocalOrdinal>
350 return ExportData_->exportLIDs_();
353 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
354 Teuchos::ArrayView<const int>
356 return ExportData_->exportPIDs_();
359 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
360 Teuchos::RCP<const typename Export<LocalOrdinal,GlobalOrdinal,Node>::map_type>
362 return ExportData_->source_;
365 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
366 Teuchos::RCP<const typename Export<LocalOrdinal,GlobalOrdinal,Node>::map_type>
368 return ExportData_->target_;
371 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
374 return ExportData_->distributor_;
377 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
380 return ExportData_->isLocallyComplete_;
383 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
388 ExportData_ = rhs.ExportData_;
393 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
397 const Teuchos::EVerbosityLevel verbLevel)
const 400 this->describeImpl (out,
"Tpetra::Export", verbLevel);
403 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
407 auto out = Teuchos::getFancyOStream (Teuchos::rcpFromRef (os));
409 this->describe (*out, Teuchos::VERB_EXTREME);
412 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
418 using Teuchos::Array;
419 using Teuchos::ArrayRCP;
420 using Teuchos::ArrayView;
423 typedef LocalOrdinal LO;
424 typedef GlobalOrdinal GO;
425 typedef typename ArrayView<const GO>::size_type size_type;
426 const char tfecfFuncName[] =
"setupExport: ";
428 const map_type& source = * (getSourceMap ());
429 const map_type& target = * (getTargetMap ());
430 ArrayView<const GO> sourceGIDs = source.getNodeElementList ();
431 ArrayView<const GO> targetGIDs = target.getNodeElementList ();
433 #ifdef HAVE_TPETRA_DEBUG 434 ArrayView<const GO> rawSrcGids = sourceGIDs;
435 ArrayView<const GO> rawTgtGids = targetGIDs;
437 const GO*
const rawSrcGids = sourceGIDs.getRawPtr ();
438 const GO*
const rawTgtGids = targetGIDs.getRawPtr ();
439 #endif // HAVE_TPETRA_DEBUG 440 const size_type numSrcGids = sourceGIDs.size ();
441 const size_type numTgtGids = targetGIDs.size ();
442 const size_type numGids = std::min (numSrcGids, numTgtGids);
450 size_type numSameGids = 0;
451 for ( ; numSameGids < numGids && rawSrcGids[numSameGids] == rawTgtGids[numSameGids]; ++numSameGids)
453 ExportData_->numSameIDs_ = numSameGids;
465 exportGIDs.resize (0);
466 Array<LO>& permuteToLIDs = ExportData_->permuteToLIDs_;
467 Array<LO>& permuteFromLIDs = ExportData_->permuteFromLIDs_;
468 Array<LO>& exportLIDs = ExportData_->exportLIDs_;
469 const LO LINVALID = Teuchos::OrdinalTraits<LO>::invalid ();
470 const LO numSrcLids = as<LO> (numSrcGids);
473 for (LO srcLid = numSameGids; srcLid < numSrcLids; ++srcLid) {
474 const GO curSrcGid = rawSrcGids[srcLid];
477 const LO tgtLid = target.getLocalElement (curSrcGid);
478 if (tgtLid != LINVALID) {
479 permuteToLIDs.push_back (tgtLid);
480 permuteFromLIDs.push_back (srcLid);
482 exportGIDs.push_back (curSrcGid);
483 exportLIDs.push_back (srcLid);
494 if (exportLIDs.size () != 0 && ! source.isDistributed ()) {
500 ExportData_->isLocallyComplete_ =
false;
504 (
true, std::runtime_error,
"::setupSamePermuteExport(): Source has " 505 "export LIDs but Source is not distributed globally. Exporting to " 506 "a submap of the target map.");
520 if (source.isDistributed ()) {
521 ExportData_->exportPIDs_.resize(exportGIDs.size ());
526 target.getRemoteIndexList (exportGIDs(),
527 ExportData_->exportPIDs_ ());
531 "::setupSamePermuteExport(): The source Map has GIDs not found " 532 "in the target Map.");
541 ExportData_->isLocallyComplete_ =
false;
543 const size_type numInvalidExports =
544 std::count_if (ExportData_->exportPIDs_().begin(),
545 ExportData_->exportPIDs_().end(),
546 std::bind1st (std::equal_to<int>(), -1));
547 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
548 (numInvalidExports == 0, std::logic_error,
"Calling getRemoteIndexList " 549 "on the target Map returned IDNotPresent, but none of the returned " 550 "\"export\" process ranks are -1. Please report this bug to the " 551 "Tpetra developers.");
554 const size_type totalNumExports = ExportData_->exportPIDs_.size();
555 if (numInvalidExports == totalNumExports) {
557 exportGIDs.resize(0);
558 ExportData_->exportLIDs_.resize(0);
559 ExportData_->exportPIDs_.resize(0);
564 size_type numValidExports = 0;
565 for (size_type e = 0; e < totalNumExports; ++e) {
566 if (ExportData_->exportPIDs_[e] != -1) {
567 exportGIDs[numValidExports] = exportGIDs[e];
568 ExportData_->exportLIDs_[numValidExports] = ExportData_->exportLIDs_[e];
569 ExportData_->exportPIDs_[numValidExports] = ExportData_->exportPIDs_[e];
573 exportGIDs.resize (numValidExports);
574 ExportData_->exportLIDs_.resize (numValidExports);
575 ExportData_->exportPIDs_.resize (numValidExports);
581 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
583 Export<LocalOrdinal,GlobalOrdinal,Node>::setupRemote(Teuchos::Array<GlobalOrdinal> & exportGIDs)
585 using Teuchos::Array;
588 const map_type& target = * (getTargetMap ());
589 const int myRank = target.getComm ()->getRank ();
591 if (! out_.is_null ()) {
595 std::ostringstream os;
596 os << myRank <<
": Export::setupRemote" << endl;
599 if (! out_.is_null ()) {
607 sort3 (ExportData_->exportPIDs_.begin(),
608 ExportData_->exportPIDs_.end(),
610 ExportData_->exportLIDs_.begin());
613 std::ostringstream os;
614 os << myRank <<
": Export::setupRemote: Calling createFromSends" << endl;
625 numRemoteIDs = ExportData_->distributor_.createFromSends (ExportData_->exportPIDs_ ());
628 std::ostringstream os;
629 os << myRank <<
": Export::setupRemote: Calling doPostsAndWaits" << endl;
636 Array<GlobalOrdinal> remoteGIDs (numRemoteIDs);
637 ExportData_->distributor_.doPostsAndWaits (exportGIDs().getConst (), 1, remoteGIDs());
641 ExportData_->remoteLIDs_.resize (numRemoteIDs);
643 typename Array<GlobalOrdinal>::const_iterator i = remoteGIDs.begin();
644 typename Array<LocalOrdinal>::iterator j = ExportData_->remoteLIDs_.begin();
645 while (i != remoteGIDs.end()) {
646 *j++ = target.getLocalElement(*i++);
650 if (! out_.is_null ()) {
654 std::ostringstream os;
655 os << myRank <<
": Export::setupRemote: done" << endl;
658 if (! out_.is_null ()) {
672 #define TPETRA_EXPORT_INSTANT(LO, GO, NODE) \ 674 template class Export< LO , GO , NODE >; 676 #endif // TPETRA_EXPORT_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.
Teuchos::ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
Distributor & getDistributor() const
The Distributor that this Export object uses to move data.
size_t getNumSameIDs() const
Number of initial identical IDs.
size_t getNumExportIDs() const
Number of entries that must be sent by the calling process to other processes.
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()).
bool isLocallyComplete() const
Do all source Map indices on the calling process exist on at least one process (not necessarily this ...
size_t getNumPermuteIDs() const
Number of IDs to permute but not to communicate.
Teuchos::ArrayView< const int > getExportPIDs() const
List of processes to which entries will be sent.
Teuchos::ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
Teuchos::RCP< const map_type > getSourceMap() const
The source Map used to construct this Export.
Export(const Teuchos::RCP< const map_type > &source, const Teuchos::RCP< const map_type > &target)
Construct a Export object from the source and target Map.
Export< LocalOrdinal, GlobalOrdinal, Node > & operator=(const Export< LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator.
Teuchos::ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
size_t getNumRemoteIDs() const
Number of entries not on the calling process.
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...
Implementation detail of Import and Export.
Sets up and executes a communication plan for a Tpetra DistObject.
Stand-alone utility functions and macros.
virtual void print(std::ostream &os) const
Print the Export's data to the given output stream.
virtual ~Export()
Destructor.
Teuchos::ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set parameters.
Teuchos::RCP< const map_type > getTargetMap() const
The target Map used to construct this Export.
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.