42 #ifndef TPETRA_DISTOBJECT_DEF_HPP
43 #define TPETRA_DISTOBJECT_DEF_HPP
45 #include "Tpetra_ConfigDefs.hpp"
46 #include "Tpetra_Map.hpp"
47 #include "Tpetra_Import.hpp"
48 #include "Tpetra_Export.hpp"
49 #include "Tpetra_Distributor.hpp"
51 #ifdef DOXYGEN_USE_ONLY
52 # include "Tpetra_DistObject_decl.hpp"
53 #endif // DOXYGEN_USE_ONLY
57 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
65 using Teuchos::TimeMonitor;
67 RCP<Time> doXferTimer =
68 TimeMonitor::lookupCounter (
"Tpetra::DistObject::doTransfer");
69 if (doXferTimer.is_null ()) {
71 TimeMonitor::getNewCounter (
"Tpetra::DistObject::doTransfer");
73 doXferTimer_ = doXferTimer;
75 RCP<Time> copyAndPermuteTimer =
76 TimeMonitor::lookupCounter (
"Tpetra::DistObject::copyAndPermute");
77 if (copyAndPermuteTimer.is_null ()) {
79 TimeMonitor::getNewCounter (
"Tpetra::DistObject::copyAndPermute");
81 copyAndPermuteTimer_ = copyAndPermuteTimer;
83 RCP<Time> packAndPrepareTimer =
84 TimeMonitor::lookupCounter (
"Tpetra::DistObject::packAndPrepare");
85 if (packAndPrepareTimer.is_null ()) {
87 TimeMonitor::getNewCounter (
"Tpetra::DistObject::packAndPrepare");
89 packAndPrepareTimer_ = packAndPrepareTimer;
91 RCP<Time> doPostsAndWaitsTimer =
92 TimeMonitor::lookupCounter (
"Tpetra::DistObject::doPostsAndWaits");
93 if (doPostsAndWaitsTimer.is_null ()) {
94 doPostsAndWaitsTimer =
95 TimeMonitor::getNewCounter (
"Tpetra::DistObject::doPostsAndWaits");
97 doPostsAndWaitsTimer_ = doPostsAndWaitsTimer;
99 RCP<Time> unpackAndCombineTimer =
100 TimeMonitor::lookupCounter (
"Tpetra::DistObject::unpackAndCombine");
101 if (unpackAndCombineTimer.is_null ()) {
102 unpackAndCombineTimer =
103 TimeMonitor::getNewCounter (
"Tpetra::DistObject::unpackAndCombine");
105 unpackAndCombineTimer_ = unpackAndCombineTimer;
106 #endif // HAVE_TPETRA_TRANSFER_TIMERS
109 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
115 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
119 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 using Teuchos::TypeNameTraits;
125 std::ostringstream os;
126 os <<
"Tpetra::DistObject<"
127 << TypeNameTraits<Packet>::name ()
128 <<
", " << TypeNameTraits<LocalOrdinal>::name ()
129 <<
", " << TypeNameTraits<GlobalOrdinal>::name ()
130 <<
", " << TypeNameTraits<Node>::name ()
135 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 const Teuchos::EVerbosityLevel verbLevel)
const
141 using Teuchos::rcpFromRef;
144 const Teuchos::EVerbosityLevel vl = (verbLevel == Teuchos::VERB_DEFAULT) ?
145 Teuchos::VERB_LOW : verbLevel;
147 if (vl != Teuchos::VERB_NONE) {
148 out << this->description () << endl;
149 Teuchos::OSTab tab (rcpFromRef (out));
150 out <<
"Export buffer size (in packets): " << exports_.size() << endl
151 <<
"Import buffer size (in packets): " << imports_.size() << endl
152 <<
"Map over which this object is distributed:" << endl;
153 map_->describe (out, vl);
157 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
162 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
163 "Tpetra::DistObject::removeEmptyProcessesInPlace: Not implemented");
166 template<
class DistObjectType>
169 const Teuchos::RCP<
const Map<
typename DistObjectType::local_ordinal_type,
170 typename DistObjectType::global_ordinal_type,
171 typename DistObjectType::node_type> >& newMap)
173 input->removeEmptyProcessesInPlace (newMap);
174 if (newMap.is_null ()) {
175 input = Teuchos::null;
179 template<
class DistObjectType>
184 typedef typename DistObjectType::local_ordinal_type LO;
185 typedef typename DistObjectType::global_ordinal_type GO;
186 typedef typename DistObjectType::node_type NT;
190 removeEmptyProcessesInPlace<DistObjectType> (input, newMap);
193 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
200 TEUCHOS_TEST_FOR_EXCEPTION(*getMap() != *importer.
getTargetMap(),
201 std::invalid_argument,
"doImport: The target DistObject's Map is not "
202 "identical to the Import's target Map.");
203 #ifdef HAVE_TPETRA_DEBUG
206 const this_type* srcDistObj =
dynamic_cast<const this_type*
> (&source);
207 TEUCHOS_TEST_FOR_EXCEPTION(
208 srcDistObj != NULL && * (srcDistObj->getMap ()) != *importer.
getSourceMap(),
209 std::invalid_argument,
"doImport: The source is a DistObject, yet its "
210 "Map is not identical to the Import's source Map.");
212 #endif // HAVE_TPETRA_DEBUG
215 typedef Teuchos::ArrayView<const LocalOrdinal> view_type;
220 this->doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs,
225 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
232 TEUCHOS_TEST_FOR_EXCEPTION(
233 *getMap() != *exporter.
getTargetMap(), std::invalid_argument,
234 "doExport: The target DistObject's Map is not identical to the Export's "
236 #ifdef HAVE_TPETRA_DEBUG
239 const this_type* srcDistObj =
dynamic_cast<const this_type*
> (&source);
240 TEUCHOS_TEST_FOR_EXCEPTION(
241 srcDistObj != NULL && * (srcDistObj->getMap ()) != *exporter.
getSourceMap(),
242 std::invalid_argument,
"doExport: The source is a DistObject, yet its "
243 "Map is not identical to the Export's source Map.");
245 #endif // HAVE_TPETRA_DEBUG
248 typedef ArrayView<const LocalOrdinal> view_type;
253 doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
257 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
264 TEUCHOS_TEST_FOR_EXCEPTION(
265 *getMap() != *exporter.
getSourceMap(), std::invalid_argument,
266 "doImport (reverse mode): The target DistObject's Map is not identical "
267 "to the Export's source Map.");
268 #ifdef HAVE_TPETRA_DEBUG
271 const this_type* srcDistObj =
dynamic_cast<const this_type*
> (&source);
272 TEUCHOS_TEST_FOR_EXCEPTION(
273 srcDistObj != NULL && * (srcDistObj->getMap ()) != *exporter.
getTargetMap(),
274 std::invalid_argument,
275 "doImport (reverse mode): The source is a DistObject, yet its "
276 "Map is not identical to the Export's target Map.");
278 #endif // HAVE_TPETRA_DEBUG
281 typedef ArrayView<const LocalOrdinal> view_type;
286 doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
290 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
297 TEUCHOS_TEST_FOR_EXCEPTION(
298 *getMap() != *importer.
getSourceMap(), std::invalid_argument,
299 "doExport (reverse mode): The target object's Map "
300 "is not identical to the Import's source Map.");
301 #ifdef HAVE_TPETRA_DEBUG
304 const this_type* srcDistObj =
dynamic_cast<const this_type*
> (&source);
305 TEUCHOS_TEST_FOR_EXCEPTION(
306 srcDistObj != NULL && * (srcDistObj->getMap ()) != *importer.
getTargetMap(),
307 std::invalid_argument,
308 "doExport (reverse mode): The source is a DistObject, yet its "
309 "Map is not identical to the Import's target Map.");
311 #endif // HAVE_TPETRA_DEBUG
314 typedef ArrayView<const LocalOrdinal> view_type;
319 doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
323 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
326 return map_->isDistributed ();
329 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
336 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
342 const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
343 const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs,
344 const Teuchos::ArrayView<const LocalOrdinal>& remoteLIDs,
345 const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
350 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
351 Teuchos::TimeMonitor doXferMon (*doXferTimer_);
352 #endif // HAVE_TPETRA_TRANSFER_TIMERS
354 TEUCHOS_TEST_FOR_EXCEPTION(
355 ! checkSizes (src), std::invalid_argument,
356 "Tpetra::DistObject::doTransfer(): checkSizes() indicates that the "
357 "destination object is not a legal target for redistribution from the "
358 "source object. This probably means that they do not have the same "
359 "dimensions. For example, MultiVectors must have the same number of "
360 "rows and columns.");
361 Kokkos::ReadWriteOption rwo = Kokkos::ReadWrite;
363 const size_t numIDsToWrite = numSameIDs +
364 as<size_t> (permuteToLIDs.size ()) +
365 as<size_t> (remoteLIDs.size ());
366 if (numIDsToWrite == this->getMap ()->getNodeNumElements ()) {
374 rwo = Kokkos::WriteOnly;
386 const this_type* srcDistObj =
dynamic_cast<const this_type*
> (&src);
387 if (srcDistObj != NULL) {
403 this->createViewsNonConst (rwo);
405 if (numSameIDs + permuteToLIDs.size()) {
406 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
407 Teuchos::TimeMonitor copyAndPermuteMon (*copyAndPermuteTimer_);
408 #endif // HAVE_TPETRA_TRANSFER_TIMERS
410 copyAndPermute (src, numSameIDs, permuteToLIDs, permuteFromLIDs);
417 size_t constantNumPackets = this->constantNumberOfPackets ();
419 if (constantNumPackets == 0) {
420 numExportPacketsPerLID_.resize (exportLIDs.size ());
421 numImportPacketsPerLID_.resize (remoteLIDs.size ());
425 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
426 Teuchos::TimeMonitor packAndPrepareMon (*packAndPrepareTimer_);
427 #endif // HAVE_TPETRA_TRANSFER_TIMERS
433 packAndPrepare (src, exportLIDs, exports_, numExportPacketsPerLID_ (),
434 constantNumPackets, distor);
441 if (srcDistObj != NULL) {
442 srcDistObj->releaseViews ();
445 if (constantNumPackets != 0) {
450 const size_t rbufLen = remoteLIDs.size() * constantNumPackets;
451 if (as<size_t> (imports_.size()) != rbufLen) {
452 imports_.resize (rbufLen);
457 bool needCommunication =
true;
458 if (revOp == DoReverse && ! isDistributed ()) {
459 needCommunication =
false;
468 else if (revOp == DoForward && srcDistObj != NULL && ! srcDistObj->isDistributed ()) {
469 needCommunication =
false;
472 if (needCommunication) {
473 if (revOp == DoReverse) {
474 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
475 Teuchos::TimeMonitor doPostsAndWaitsMon (*doPostsAndWaitsTimer_);
476 #endif // HAVE_TPETRA_TRANSFER_TIMERS
477 if (constantNumPackets == 0) {
479 numImportPacketsPerLID_());
480 size_t totalImportPackets = 0;
482 totalImportPackets += numImportPacketsPerLID_[i];
484 imports_.resize(totalImportPackets);
486 numExportPacketsPerLID_(),
488 numImportPacketsPerLID_());
497 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
498 Teuchos::TimeMonitor doPostsAndWaitsMon (*doPostsAndWaitsTimer_);
499 #endif // HAVE_TPETRA_TRANSFER_TIMERS
500 if (constantNumPackets == 0) {
502 numImportPacketsPerLID_());
503 size_t totalImportPackets = 0;
505 totalImportPackets += numImportPacketsPerLID_[i];
507 imports_.resize(totalImportPackets);
509 numExportPacketsPerLID_(),
511 numImportPacketsPerLID_());
520 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
521 Teuchos::TimeMonitor unpackAndCombineMon (*unpackAndCombineTimer_);
522 #endif // HAVE_TPETRA_TRANSFER_TIMERS
523 unpackAndCombine (remoteLIDs, imports_(), numImportPacketsPerLID_(),
524 constantNumPackets, distor, CM);
527 this->releaseViews();
530 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
534 using Teuchos::FancyOStream;
535 using Teuchos::getFancyOStream;
537 using Teuchos::rcpFromRef;
540 RCP<FancyOStream> out = getFancyOStream (rcpFromRef (os));
541 this->describe (*out, Teuchos::VERB_DEFAULT);
544 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
549 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
555 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
561 #define TPETRA_DISTOBJECT_INSTANT(SCALAR, LO, GO, NODE) \
563 template class DistObject< SCALAR , LO , GO , NODE >;
566 #define TPETRA_DISTOBJECT_INSTANT_CHAR(LO, GO, NODE) \
568 template class DistObject< char , LO , GO , NODE >;
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
virtual void createViewsNonConst(Kokkos::ReadWriteOption rwo)
Hook for creating a nonconst view.
ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
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 RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getSourceMap() const
The source Map used to construct this Export.
virtual void createViews() const
Hook for creating a const view.
size_t getNumSameIDs() const
Number of initial identical IDs.
void print(std::ostream &os) const
Print this object to the given output stream.
bool isDistributed() const
Whether this is a globally distributed object.
void removeEmptyProcessesInPlace(Teuchos::RCP< DistObjectType > &input, const Teuchos::RCP< const Map< typename DistObjectType::local_ordinal_type, typename DistObjectType::global_ordinal_type, typename DistObjectType::node_type > > &newMap)
Remove processes which contain no elements in this object's Map.
ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
virtual void releaseViews() const
Hook for releasing views.
Teuchos_Ordinal Array_size_type
Size type for Teuchos Array objects.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
Remove processes which contain no elements in this object's Map.
ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
void doPostsAndWaits(const ArrayView< const Packet > &exports, size_t numPackets, const ArrayView< Packet > &imports)
Execute the (forward) communication plan.
DistObject(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Constructor.
virtual ~DistObject()
Destructor (virtual for memory safety of derived classes).
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...
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
Abstract base class for objects that can be the source of an Import or Export operation.
ReverseOption
Whether the data transfer should be performed in forward or reverse mode.
ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
virtual std::string description() const
One-line descriptiion of this object.
virtual size_t constantNumberOfPackets() const
Whether the implementation's instance promises always to have a constant number of packets per LID...
void doReversePostsAndWaits(const ArrayView< const Packet > &exports, size_t numPackets, const ArrayView< Packet > &imports)
Execute the reverse communication plan.
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.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getTargetMap() const
The target Map used to construct this Export.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getSourceMap() const
The Source Map used to construct this Import object.
Distributor & getDistributor() const
The Distributor that this Export object uses to move data.
size_t getNumSameIDs() const
Number of initial identical IDs.
Distributor & getDistributor() const
The Distributor that this Import object uses to move data.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print a descriptiion of this object to the given output stream.
void doImport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import data into this object using an Import object ("forward mode").
Base class for distributed Tpetra objects that support data redistribution.
void doExport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export data into this object using an Export object ("forward mode").
virtual void doTransfer(const SrcDistObject &src, CombineMode CM, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs, const Teuchos::ArrayView< const LocalOrdinal > &remoteLIDs, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Distributor &distor, ReverseOption revOp)
Redistribute data across memory images.