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 68 TimeMonitor::lookupCounter (
"Tpetra::DistObject::doTransfer");
71 TimeMonitor::getNewCounter (
"Tpetra::DistObject::doTransfer");
73 doXferTimer_ = doXferTimer;
76 TimeMonitor::lookupCounter (
"Tpetra::DistObject::copyAndPermute");
77 if (copyAndPermuteTimer.
is_null ()) {
79 TimeMonitor::getNewCounter (
"Tpetra::DistObject::copyAndPermute");
81 copyAndPermuteTimer_ = copyAndPermuteTimer;
84 TimeMonitor::lookupCounter (
"Tpetra::DistObject::packAndPrepare");
85 if (packAndPrepareTimer.
is_null ()) {
87 TimeMonitor::getNewCounter (
"Tpetra::DistObject::packAndPrepare");
89 packAndPrepareTimer_ = packAndPrepareTimer;
92 TimeMonitor::lookupCounter (
"Tpetra::DistObject::doPostsAndWaits");
93 if (doPostsAndWaitsTimer.
is_null ()) {
94 doPostsAndWaitsTimer =
95 TimeMonitor::getNewCounter (
"Tpetra::DistObject::doPostsAndWaits");
97 doPostsAndWaitsTimer_ = doPostsAndWaitsTimer;
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>
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>
141 using Teuchos::rcpFromRef;
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>
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>
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);
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 220 this->
doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs,
225 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
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 253 doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
257 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
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 286 doTransfer (source, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs,
290 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
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 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>
350 #ifdef HAVE_TPETRA_TRANSFER_TIMERS 352 #endif // HAVE_TPETRA_TRANSFER_TIMERS 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) {
405 if (numSameIDs + permuteToLIDs.
size()) {
406 #ifdef HAVE_TPETRA_TRANSFER_TIMERS 408 #endif // HAVE_TPETRA_TRANSFER_TIMERS 419 if (constantNumPackets == 0) {
420 numExportPacketsPerLID_.
resize (exportLIDs.
size ());
421 numImportPacketsPerLID_.
resize (remoteLIDs.
size ());
425 #ifdef HAVE_TPETRA_TRANSFER_TIMERS 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;
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 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 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 522 #endif // HAVE_TPETRA_TRANSFER_TIMERS 524 constantNumPackets, distor, CM);
530 template <
class Packet,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
535 using Teuchos::getFancyOStream;
537 using Teuchos::rcpFromRef;
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.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
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 packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< Packet > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)=0
Perform any packing or preparation required for communication.
virtual void createViews() const
Hook for creating a const view.
size_t getNumSameIDs() const
Number of initial identical IDs.
basic_FancyOStream< char > FancyOStream
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void print(std::ostream &os) const
Print this object to the given output stream.
bool isDistributed() const
Whether this is a globally distributed object.
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.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getMap() const
The Map describing the parallel distribution of this object.
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs)=0
Perform copies and permutations that are local to this process.
ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
Abstract base class for objects that can be the source of an Import or Export operation.
void resize(size_type new_size, const value_type &x=value_type())
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.
TypeTo as(const TypeFrom &t)
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").
virtual void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const Packet > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode CM)=0
Perform any unpacking and combining after communication.
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.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > map_
The Map over which this object is distributed.
virtual bool checkSizes(const SrcDistObject &source)=0
Compare the source and target (this) objects for compatibility.