42 #ifndef TPETRA_EXPORT_DEF_HPP 43 #define TPETRA_EXPORT_DEF_HPP 45 #ifdef DOXYGEN_USE_ONLY 46 # include <Tpetra_Export_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_Import.hpp> 58 const bool tpetraExportDebugDefault =
false;
62 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 Export<LocalOrdinal,GlobalOrdinal,Node>::
67 bool debug = tpetraExportDebugDefault;
70 debug = plist->
get<
bool> (
"Debug");
74 ExportData_->distributor_.setParameterList (plist);
77 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 debug_ (tpetraExportDebugDefault)
92 std::ostringstream os;
93 const int myRank = source->getComm ()->getRank ();
94 os << myRank <<
": Export ctor" << endl;
97 ExportData_ =
rcp (
new data_type (source, target, out_));
99 setupSamePermuteExport (exportGIDs);
101 std::ostringstream os;
102 const int myRank = source->getComm ()->getRank ();
103 os << myRank <<
": Export ctor: " 104 <<
"setupSamePermuteExport done" << endl;
107 if (source->isDistributed ()) {
108 setupRemote (exportGIDs);
111 std::ostringstream os;
112 const int myRank = source->getComm ()->getRank ();
113 os << myRank <<
": Export ctor: done" << endl;
121 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
127 debug_ (tpetraExportDebugDefault)
137 std::ostringstream os;
138 const int myRank = source->getComm ()->getRank ();
139 os << myRank <<
": Export ctor" << endl;
142 ExportData_ =
rcp (
new data_type (source, target, out));
144 setupSamePermuteExport (exportGIDs);
146 std::ostringstream os;
147 const int myRank = source->getComm ()->getRank ();
148 os << myRank <<
": Export ctor: " 149 <<
"setupSamePermuteExport done" << endl;
152 if (source->isDistributed ()) {
153 setupRemote (exportGIDs);
156 std::ostringstream os;
157 const int myRank = source->getComm ()->getRank ();
158 os << myRank <<
": Export ctor: done" << endl;
166 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
171 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
172 debug_ (tpetraExportDebugDefault)
179 bool debug = tpetraExportDebugDefault;
182 debug = plist->
get<
bool> (
"Debug");
191 std::ostringstream os;
192 const int myRank = source->getComm ()->getRank ();
193 os << myRank <<
": Export ctor" << endl;
196 ExportData_ =
rcp (
new data_type (source, target, out_, plist));
198 setupSamePermuteExport (exportGIDs);
200 std::ostringstream os;
201 const int myRank = source->getComm ()->getRank ();
202 os << myRank <<
": Export ctor: " 203 <<
"setupSamePermuteExport done" << endl;
206 if (source->isDistributed ()) {
207 setupRemote (exportGIDs);
210 std::ostringstream os;
211 const int myRank = source->getComm ()->getRank ();
212 os << myRank <<
": Export ctor: done" << endl;
220 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 out_ (
Teuchos::getFancyOStream (
Teuchos::rcpFromRef (std::cerr))),
227 debug_ (tpetraExportDebugDefault)
234 bool debug = tpetraExportDebugDefault;
237 debug = plist->
get<
bool> (
"Debug");
246 std::ostringstream os;
247 const int myRank = source->getComm ()->getRank ();
248 os << myRank <<
": Export ctor" << endl;
251 ExportData_ =
rcp (
new data_type (source, target, out, plist));
253 setupSamePermuteExport (exportGIDs);
255 std::ostringstream os;
256 const int myRank = source->getComm ()->getRank ();
257 os << myRank <<
": Export ctor: " 258 <<
"setupSamePermuteExport done" << endl;
261 if (source->isDistributed ()) {
262 setupRemote (exportGIDs);
265 std::ostringstream os;
266 const int myRank = source->getComm ()->getRank ();
267 os << myRank <<
": Export ctor: done" << endl;
275 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
278 : ExportData_ (rhs.ExportData_),
288 std::ostringstream os;
289 const int myRank =
getSourceMap ()->getComm ()->getRank ();
290 os << myRank <<
": Export copy ctor (done)" << endl;
298 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301 : out_ (importer.out_)
302 , debug_ (importer.debug_)
304 if(!importer.ImportData_.is_null()) ExportData_ = importer.ImportData_->reverseClone();
307 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 return ExportData_->numSameIDs_;
316 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
318 return ExportData_->permuteFromLIDs_.size();
321 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
324 return ExportData_->permuteFromLIDs_();
327 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
330 return ExportData_->permuteToLIDs_();
333 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
335 return ExportData_->remoteLIDs_.size();
338 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
341 return ExportData_->remoteLIDs_();
344 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
346 return ExportData_->exportLIDs_.size();
349 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
352 return ExportData_->exportLIDs_();
355 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
358 return ExportData_->exportPIDs_();
361 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
364 return ExportData_->source_;
367 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
370 return ExportData_->target_;
373 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
376 return ExportData_->distributor_;
379 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
384 ExportData_ = rhs.ExportData_;
389 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
394 using Teuchos::getFancyOStream;
396 using Teuchos::rcpFromRef;
401 const int myImageID = comm->getRank ();
402 const int numImages = comm->getSize ();
403 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
404 if (myImageID == imageCtr) {
406 if (myImageID == 0) {
407 os <<
"Export Data Members:" << endl;
409 os <<
"Image ID : " << myImageID << endl;
427 if (myImageID == 0) {
428 os << endl << endl <<
"Source Map:" << endl << std::flush;
434 if (myImageID == 0) {
435 os << endl << endl <<
"Target Map:" << endl << std::flush;
444 if (myImageID == 0) {
445 os << endl << endl <<
"Distributor:" << endl << std::flush;
453 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
464 typedef LocalOrdinal LO;
465 typedef GlobalOrdinal GO;
472 #ifdef HAVE_TPETRA_DEBUG 476 const GO*
const rawSrcGids = sourceGIDs.
getRawPtr ();
477 const GO*
const rawTgtGids = targetGIDs.
getRawPtr ();
478 #endif // HAVE_TPETRA_DEBUG 479 const size_type numSrcGids = sourceGIDs.
size ();
480 const size_type numTgtGids = targetGIDs.
size ();
481 const size_type numGids = std::min (numSrcGids, numTgtGids);
489 size_type numSameGids = 0;
490 for ( ; numSameGids < numGids && rawSrcGids[numSameGids] == rawTgtGids[numSameGids]; ++numSameGids)
492 ExportData_->numSameIDs_ = numSameGids;
505 Array<LO>& permuteToLIDs = ExportData_->permuteToLIDs_;
506 Array<LO>& permuteFromLIDs = ExportData_->permuteFromLIDs_;
507 Array<LO>& exportLIDs = ExportData_->exportLIDs_;
509 const LO numSrcLids = as<LO> (numSrcGids);
512 for (LO srcLid = numSameGids; srcLid < numSrcLids; ++srcLid) {
513 const GO curSrcGid = rawSrcGids[srcLid];
517 if (tgtLid != LINVALID) {
536 "::setupSamePermuteExport(): Source has export LIDs but Source is not " 537 "distributed globally." << std::endl
538 <<
"Exporting to a submap of the target map.");
552 ExportData_->exportPIDs_.resize(exportGIDs.
size ());
558 ExportData_->exportPIDs_ ());
560 "::setupSamePermuteExport(): The source Map has GIDs not found " 561 "in the target Map.");
568 const size_type numInvalidExports =
569 std::count_if (ExportData_->exportPIDs_().begin(),
570 ExportData_->exportPIDs_().end(),
571 std::bind1st (std::equal_to<int>(), -1));
574 const size_type totalNumExports = ExportData_->exportPIDs_.size();
575 if (numInvalidExports == totalNumExports) {
578 ExportData_->exportLIDs_.resize(0);
579 ExportData_->exportPIDs_.resize(0);
584 size_type numValidExports = 0;
585 for (size_type e = 0; e < totalNumExports; ++e) {
586 if (ExportData_->exportPIDs_[e] != -1) {
587 exportGIDs[numValidExports] = exportGIDs[e];
588 ExportData_->exportLIDs_[numValidExports] = ExportData_->exportLIDs_[e];
589 ExportData_->exportPIDs_[numValidExports] = ExportData_->exportPIDs_[e];
593 exportGIDs.
resize (numValidExports);
594 ExportData_->exportLIDs_.resize (numValidExports);
595 ExportData_->exportPIDs_.resize (numValidExports);
601 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
607 const int myRank = target.
getComm ()->getRank ();
613 std::ostringstream os;
614 os << myRank <<
": Export::setupRemote" << endl;
625 sort3 (ExportData_->exportPIDs_.begin(),
626 ExportData_->exportPIDs_.end(),
628 ExportData_->exportLIDs_.begin());
631 std::ostringstream os;
632 os << myRank <<
": Export::setupRemote: Calling createFromSends" << endl;
643 numRemoteIDs = ExportData_->distributor_.createFromSends (ExportData_->exportPIDs_ ());
646 std::ostringstream os;
647 os << myRank <<
": Export::setupRemote: Calling doPostsAndWaits" << endl;
655 ExportData_->distributor_.doPostsAndWaits (exportGIDs().
getConst (), 1, remoteGIDs());
659 ExportData_->remoteLIDs_.resize (numRemoteIDs);
663 while (i != remoteGIDs.
end()) {
672 std::ostringstream os;
673 os << myRank <<
": Export::setupRemote: done" << endl;
689 #define TPETRA_EXPORT_INSTANT(LO, GO, NODE) \ 691 template class Export< LO , GO , NODE >; 693 #endif // TPETRA_EXPORT_DEF_HPP Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
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.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getSourceMap() const
The source Map used to construct this Export.
virtual void print(std::ostream &os) const
Print the Export's data to the given output stream.
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
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.
T & get(const std::string &name, T def_value)
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
void pushTab(const int tabs=1)
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
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.
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.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
void push_back(const value_type &x)
Describes a parallel distribution of objects over processes.
TypeTo as(const TypeFrom &t)
ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
Stand-alone utility functions and macros.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getTargetMap() const
The target Map used to construct this Export.
Distributor & getDistributor() const
The Distributor that this Export object uses to move data.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream.
std::string toString(const T &t)