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>
62 Export<LocalOrdinal,GlobalOrdinal,Node>::
63 setParameterList (
const Teuchos::RCP<Teuchos::ParameterList>& plist)
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 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 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 ArrayView<const LocalOrdinal>
322 return ExportData_->permuteFromLIDs_();
325 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
326 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 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 ArrayView<const LocalOrdinal>
350 return ExportData_->exportLIDs_();
353 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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>
382 ExportData_ = rhs.ExportData_;
387 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
392 using Teuchos::getFancyOStream;
394 using Teuchos::rcpFromRef;
395 using Teuchos::toString;
398 RCP<const Comm<int> > comm =
getSourceMap ()->getComm ();
399 const int myImageID = comm->getRank ();
400 const int numImages = comm->getSize ();
401 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
402 if (myImageID == imageCtr) {
404 if (myImageID == 0) {
405 os <<
"Export Data Members:" << endl;
407 os <<
"Image ID : " << myImageID << endl;
411 os <<
"remoteLIDs : " << toString (
getRemoteLIDs ()) << endl;
412 os <<
"exportLIDs : " << toString (
getExportLIDs ()) << endl;
413 os <<
"exportPIDs : " << toString (
getExportPIDs ()) << endl;
425 if (myImageID == 0) {
426 os << endl << endl <<
"Source Map:" << endl << std::flush;
432 if (myImageID == 0) {
433 os << endl << endl <<
"Target Map:" << endl << std::flush;
442 if (myImageID == 0) {
443 os << endl << endl <<
"Distributor:" << endl << std::flush;
447 Teuchos::VERB_EXTREME);
451 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
457 using Teuchos::Array;
458 using Teuchos::ArrayRCP;
459 using Teuchos::ArrayView;
462 typedef LocalOrdinal LO;
463 typedef GlobalOrdinal GO;
464 typedef typename ArrayView<const GO>::size_type size_type;
470 #ifdef HAVE_TPETRA_DEBUG 471 ArrayView<const GO> rawSrcGids = sourceGIDs;
472 ArrayView<const GO> rawTgtGids = targetGIDs;
474 const GO*
const rawSrcGids = sourceGIDs.getRawPtr ();
475 const GO*
const rawTgtGids = targetGIDs.getRawPtr ();
476 #endif // HAVE_TPETRA_DEBUG 477 const size_type numSrcGids = sourceGIDs.size ();
478 const size_type numTgtGids = targetGIDs.size ();
479 const size_type numGids = std::min (numSrcGids, numTgtGids);
487 size_type numSameGids = 0;
488 for ( ; numSameGids < numGids && rawSrcGids[numSameGids] == rawTgtGids[numSameGids]; ++numSameGids)
490 ExportData_->numSameIDs_ = numSameGids;
502 exportGIDs.resize (0);
503 Array<LO>& permuteToLIDs = ExportData_->permuteToLIDs_;
504 Array<LO>& permuteFromLIDs = ExportData_->permuteFromLIDs_;
505 Array<LO>& exportLIDs = ExportData_->exportLIDs_;
506 const LO LINVALID = Teuchos::OrdinalTraits<LO>::invalid ();
507 const LO numSrcLids = as<LO> (numSrcGids);
510 for (LO srcLid = numSameGids; srcLid < numSrcLids; ++srcLid) {
511 const GO curSrcGid = rawSrcGids[srcLid];
515 if (tgtLid != LINVALID) {
516 permuteToLIDs.push_back (tgtLid);
517 permuteFromLIDs.push_back (srcLid);
519 exportGIDs.push_back (curSrcGid);
520 exportLIDs.push_back (srcLid);
534 "::setupSamePermuteExport(): Source has export LIDs but Source is not " 535 "distributed globally." << std::endl
536 <<
"Exporting to a submap of the target map.");
550 ExportData_->exportPIDs_.resize(exportGIDs.size ());
556 ExportData_->exportPIDs_ ());
558 "::setupSamePermuteExport(): The source Map has GIDs not found " 559 "in the target Map.");
565 const size_type numInvalidExports =
566 std::count_if (ExportData_->exportPIDs_().begin(),
567 ExportData_->exportPIDs_().end(),
568 std::bind1st (std::equal_to<int>(), -1));
571 const size_type totalNumExports = ExportData_->exportPIDs_.size();
572 if (numInvalidExports == totalNumExports) {
574 exportGIDs.resize(0);
575 ExportData_->exportLIDs_.resize(0);
576 ExportData_->exportPIDs_.resize(0);
581 size_type numValidExports = 0;
582 for (size_type e = 0; e < totalNumExports; ++e) {
583 if (ExportData_->exportPIDs_[e] != -1) {
584 exportGIDs[numValidExports] = exportGIDs[e];
585 ExportData_->exportLIDs_[numValidExports] = ExportData_->exportLIDs_[e];
586 ExportData_->exportPIDs_[numValidExports] = ExportData_->exportPIDs_[e];
590 exportGIDs.resize (numValidExports);
591 ExportData_->exportLIDs_.resize (numValidExports);
592 ExportData_->exportPIDs_.resize (numValidExports);
598 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
604 const int myRank = target.
getComm ()->getRank ();
606 if (! out_.is_null ()) {
610 std::ostringstream os;
611 os << myRank <<
": Export::setupRemote" << endl;
614 if (! out_.is_null ()) {
622 sort3 (ExportData_->exportPIDs_.begin(),
623 ExportData_->exportPIDs_.end(),
625 ExportData_->exportLIDs_.begin());
628 std::ostringstream os;
629 os << myRank <<
": Export::setupRemote: Calling createFromSends" << endl;
640 numRemoteIDs = ExportData_->distributor_.createFromSends (ExportData_->exportPIDs_ ());
643 std::ostringstream os;
644 os << myRank <<
": Export::setupRemote: Calling doPostsAndWaits" << endl;
651 Array<GlobalOrdinal> remoteGIDs (numRemoteIDs);
652 ExportData_->distributor_.doPostsAndWaits (exportGIDs().getConst (), 1, remoteGIDs());
656 ExportData_->remoteLIDs_.resize (numRemoteIDs);
658 typename Array<GlobalOrdinal>::const_iterator i = remoteGIDs.begin();
659 typename Array<LocalOrdinal>::iterator j = ExportData_->remoteLIDs_.begin();
660 while (i != remoteGIDs.end()) {
665 if (! out_.is_null ()) {
669 std::ostringstream os;
670 os << myRank <<
": Export::setupRemote: done" << endl;
673 if (! out_.is_null ()) {
687 #define TPETRA_EXPORT_INSTANT(LO, GO, NODE) \ 689 template class Export< LO , GO , NODE >; 691 #endif // TPETRA_EXPORT_DEF_HPP Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Teuchos::RCP< const map_type > getSourceMap() const
The source Map used to construct this Export.
ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
ArrayView< const int > getExportPIDs() const
List of processes to which entries will be sent.
virtual void print(std::ostream &os) const
Print the Export's data to the given output stream.
size_t getNumSameIDs() const
Number of initial identical IDs.
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.
size_t getNumPermuteIDs() const
Number of IDs to permute but not to communicate.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
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.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
size_t getNumExportIDs() const
Number of entries that must be sent by the calling process to other processes.
#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.
size_t getNumRemoteIDs() const
Number of entries not on the calling process.
Teuchos::RCP< const map_type > getTargetMap() const
The target Map used to construct this Export.
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.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
Describes a parallel distribution of objects over processes.
ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
Stand-alone utility functions and macros.
Distributor & getDistributor() const
The Distributor that this Export object uses to move data.
virtual ~Export()
Destructor.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream.