Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_DistObject_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // clang-format off
11 #ifndef TPETRA_DISTOBJECT_DECL_HPP
12 #define TPETRA_DISTOBJECT_DECL_HPP
13 
16 
17 #include "Tpetra_Details_DistributorActor.hpp"
18 #include "Tpetra_Map.hpp"
19 #include "Tpetra_Import.hpp"
20 #include "Tpetra_Export.hpp"
21 #include "Tpetra_SrcDistObject.hpp"
23 #include "Kokkos_ArithTraits.hpp"
24 #include <memory>
25 #include <type_traits>
26 
27 
28 namespace KokkosClassic {
33  enum ReadWriteOption {
34  ReadWrite = 0,
35  OverwriteAll = 1
36  };
37 } // namespace KokkosClassic
38 
39 namespace Tpetra {
40 
123  template<class DistObjectType>
124  void
125  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
126  const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
127  typename DistObjectType::global_ordinal_type,
128  typename DistObjectType::node_type> >& newMap);
129 
166  template<class DistObjectType>
167  void
168  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input);
169 
281  template <class Packet,
282  class LocalOrdinal,
283  class GlobalOrdinal,
284  class Node>
285  class DistObject :
286  virtual public SrcDistObject,
287  virtual public Teuchos::Describable
288  {
289  public:
291 
292 
297  using packet_type = typename ::Kokkos::ArithTraits<Packet>::val_type;
299  using local_ordinal_type = LocalOrdinal;
301  using global_ordinal_type = GlobalOrdinal;
303  using node_type = Node;
304 
306  using device_type = typename Node::device_type;
308  using execution_space = typename device_type::execution_space;
309 
312 
314 
316 
320  explicit DistObject (const Teuchos::RCP<const map_type>& map);
321 
324 
327 
330 
333 
343  virtual ~DistObject () = default;
344 
346 
348 
376  void
377  doImport (const SrcDistObject& source,
379  const CombineMode CM,
380  const bool restrictedMode = false);
381 
409  void
410  doExport (const SrcDistObject& source,
412  const CombineMode CM,
413  const bool restrictedMode = false);
414 
443  void
444  doImport (const SrcDistObject& source,
446  const CombineMode CM,
447  const bool restrictedMode = false);
448 
477  void
478  doExport (const SrcDistObject& source,
480  const CombineMode CM,
481  const bool restrictedMode = false);
482 
483  void
484  beginImport(const SrcDistObject& source,
486  const CombineMode CM,
487  const bool restrictedMode = false);
488 
489  void
490  beginExport(const SrcDistObject& source,
492  const CombineMode CM,
493  const bool restrictedMode = false);
494 
495  void
496  beginImport(const SrcDistObject& source,
498  const CombineMode CM,
499  const bool restrictedMode = false);
500 
501  void
502  beginExport(const SrcDistObject& source,
504  const CombineMode CM,
505  const bool restrictedMode = false);
506 
507  void
508  endImport(const SrcDistObject& source,
510  const CombineMode CM,
511  const bool restrictedMode = false);
512 
513  void
514  endExport(const SrcDistObject& source,
516  const CombineMode CM,
517  const bool restrictedMode = false);
518 
519  void
520  endImport(const SrcDistObject& source,
522  const CombineMode CM,
523  const bool restrictedMode = false);
524 
525  void
526  endExport(const SrcDistObject& source,
528  const CombineMode CM,
529  const bool restrictedMode = false);
530 
533  bool transferArrived() const;
534 
536 
538 
544  bool isDistributed () const;
545 
552  virtual Teuchos::RCP<const map_type> getMap () const { return map_; }
553 
555 
557 
562  void print (std::ostream& os) const;
563 
565 
567 
572  virtual std::string description () const;
573 
578  virtual void
579  describe (Teuchos::FancyOStream &out,
580  const Teuchos::EVerbosityLevel verbLevel =
581  Teuchos::Describable::verbLevel_default) const;
582 
584 
586 
633  virtual void
634  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
635 
637 
638  protected:
648  DoForward, //*!< Perform the transfer in forward mode.
649  DoReverse //*!< Perform the transfer in reverse mode.
650  };
651 
668  virtual size_t constantNumberOfPackets () const;
669 
689  virtual void
690  doTransfer (const SrcDistObject& src,
691  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
692  const char modeString[],
693  const ReverseOption revOp,
694  const CombineMode CM,
695  const bool restrictedMode);
696 
711  virtual bool
712  reallocArraysForNumPacketsPerLid (const size_t numExportLIDs,
713  const size_t numImportLIDs);
714 
715 
718  using buffer_memory_space =
719  ::Tpetra::Details::DefaultTypes::comm_buffer_memory_space<device_type>;
720 
721  public:
732  using buffer_device_type =
733  Kokkos::Device<typename device_type::execution_space,
735  protected:
741  void beginTransfer(const SrcDistObject& src,
742  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
743  const char modeString[],
744  const ReverseOption revOp,
745  const CombineMode CM,
746  const bool restrictedMode);
747 
748  void endTransfer(const SrcDistObject& src,
749  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
750  const char modeString[],
751  const ReverseOption revOp,
752  const CombineMode CM,
753  const bool restrictedMode);
754 
755  void doPostRecvs(const Details::DistributorPlan& distributorPlan,
756  size_t constantNumPackets,
757  bool commOnHost,
758  std::shared_ptr<std::string> prefix,
759  const bool canTryAliasing,
760  const CombineMode CM);
761 
762  void doPostSends(const Details::DistributorPlan& distributorPlan,
763  size_t constantNumPackets,
764  bool commOnHost,
765  std::shared_ptr<std::string> prefix);
766 
767  void doPackAndPrepare(const SrcDistObject& src,
768  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
769  size_t& constantNumPackets,
770  const execution_space &space);
771 
772  void doUnpackAndCombine(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& remoteLIDs,
773  size_t constantNumPackets,
774  CombineMode CM,
775  const execution_space &space);
776 
787 
788 
792  virtual bool
793  checkSizes (const SrcDistObject& source) = 0;
794 
824  virtual void
825  copyAndPermute (const SrcDistObject& source,
826  const size_t numSameIDs,
827  const Kokkos::DualView<const local_ordinal_type*,
828  buffer_device_type>& permuteToLIDs,
829  const Kokkos::DualView<const local_ordinal_type*,
830  buffer_device_type>& permuteFromLIDs,
831  const CombineMode CM);
832 
833  // clang-format on
836  virtual void copyAndPermute(
837  const SrcDistObject &source, const size_t numSameIDs,
838  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
839  &permuteToLIDs,
840  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
841  &permuteFromLIDs,
842  const CombineMode CM, const execution_space &space);
843  // clang-format off
844 
882  virtual void
883  packAndPrepare (const SrcDistObject& source,
884  const Kokkos::DualView<const local_ordinal_type*,
885  buffer_device_type>& exportLIDs,
886  Kokkos::DualView<packet_type*,
887  buffer_device_type>& exports,
888  Kokkos::DualView<size_t*,
889  buffer_device_type> numPacketsPerLID,
890  size_t& constantNumPackets);
891 
894  virtual void
895  packAndPrepare (const SrcDistObject& source,
896  const Kokkos::DualView<const local_ordinal_type*,
897  buffer_device_type>& exportLIDs,
898  Kokkos::DualView<packet_type*,
899  buffer_device_type>& exports,
900  Kokkos::DualView<size_t*,
901  buffer_device_type> numPacketsPerLID,
902  size_t& constantNumPackets,
903  const execution_space &space);
904 
944  virtual void
945  unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
946  buffer_device_type>& importLIDs,
947  Kokkos::DualView<packet_type*,
948  buffer_device_type> imports,
949  Kokkos::DualView<size_t*,
950  buffer_device_type> numPacketsPerLID,
951  const size_t constantNumPackets,
952  const CombineMode combineMode);
953 
954  virtual void
955  unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
956  buffer_device_type>& importLIDs,
957  Kokkos::DualView<packet_type*,
958  buffer_device_type> imports,
959  Kokkos::DualView<size_t*,
960  buffer_device_type> numPacketsPerLID,
961  const size_t constantNumPackets,
962  const CombineMode combineMode,
963  const execution_space &space);
964 
966  Teuchos::RCP<const map_type> map_;
967 
968  protected:
969  std::unique_ptr<std::string>
970  createPrefix(const char className[],
971  const char methodName[]) const;
972 
979  Kokkos::DualView<packet_type*, buffer_device_type> imports_;
980 
999  virtual bool
1000  reallocImportsIfNeeded (const size_t newSize,
1001  const bool verbose,
1002  const std::string* prefix,
1003  const bool remoteLIDsContiguous=false,
1004  const CombineMode CM=INSERT);
1005 
1019  Kokkos::DualView<size_t*, buffer_device_type> numImportPacketsPerLID_;
1020 
1026  Kokkos::DualView<packet_type*, buffer_device_type> exports_;
1027 
1041  Kokkos::DualView<size_t*, buffer_device_type> numExportPacketsPerLID_;
1042 
1043  private:
1045 
1046  Details::DistributorActor distributorActor_;
1047 
1048  }; // class DistObject
1049 } // namespace Tpetra
1050 
1051 #endif // TPETRA_DISTOBJECT_DECL_HPP
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Node node_type
The Node type. If you don&#39;t know what this is, don&#39;t use it.
Kokkos::DualView< size_t *, buffer_device_type > numExportPacketsPerLID_
Number of packets to send for each send operation.
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM)
Perform copies and permutations that are local to the calling (MPI) process.
void doImport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const CombineMode CM, const bool restrictedMode=false)
Import data into this object using an Import object (&quot;forward mode&quot;).
typename::Kokkos::ArithTraits< GlobalOrdinal >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
void print(std::ostream &os) const
Print this object to the given output stream.
virtual bool reallocArraysForNumPacketsPerLid(const size_t numExportLIDs, const size_t numImportLIDs)
Reallocate numExportPacketsPerLID_ and/or numImportPacketsPerLID_, if necessary.
Abstract base class for sources of an Import or Export.
bool isDistributed() const
Whether this is a globally distributed object.
Forward declaration of Tpetra::DistObject.
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&#39;s Map.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode)
Perform any unpacking and combining after communication.
virtual void doTransfer(const SrcDistObject &src, const ::Tpetra::Details::Transfer< local_ordinal_type, global_ordinal_type, node_type > &transfer, const char modeString[], const ReverseOption revOp, const CombineMode CM, const bool restrictedMode)
Redistribute data across (MPI) processes.
void beginTransfer(const SrcDistObject &src, const ::Tpetra::Details::Transfer< local_ordinal_type, global_ordinal_type, node_type > &transfer, const char modeString[], const ReverseOption revOp, const CombineMode CM, const bool restrictedMode)
Implementation detail of doTransfer.
virtual ~DistObject()=default
Destructor (virtual for memory safety of derived classes).
Kokkos::DualView< size_t *, buffer_device_type > numImportPacketsPerLID_
Number of packets to receive for each receive operation.
Insert new values that don&#39;t currently exist.
typename device_type::execution_space execution_space
The Kokkos execution space.
Kokkos::DualView< packet_type *, buffer_device_type > imports_
Buffer into which packed data are imported (received from other processes).
Kokkos::DualView< packet_type *, buffer_device_type > exports_
Buffer from which packed data are exported (sent to other processes).
::Tpetra::Details::DefaultTypes::comm_buffer_memory_space< device_type > buffer_memory_space
Kokkos memory space for communication buffers.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets)
Pack data and metadata for communication (sends).
CombineMode
Rule for combining data in an Import or Export.
Teuchos::RCP< const map_type > map_
The Map over which this object is distributed.
Abstract base class for objects that can be the source of an Import or Export operation.
DistObject & operator=(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &)=default
Assignment operator (default).
DistObject(const Teuchos::RCP< const map_type > &map)
Constructor.
virtual std::string description() const
One-line descriptiion of this object.
bool transferArrived() const
Whether the data from an import/export operation has arrived, and is ready for the unpack and combine...
virtual size_t constantNumberOfPackets() const
Whether the implementation&#39;s instance promises always to have a constant number of packets per LID (l...
virtual bool reallocImportsIfNeeded(const size_t newSize, const bool verbose, const std::string *prefix, const bool remoteLIDsContiguous=false, const CombineMode CM=INSERT)
Reallocate imports_ if needed.
A parallel distribution of indices over processes.
void doExport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const CombineMode CM, const bool restrictedMode=false)
Export data into this object using an Export object (&quot;forward mode&quot;).
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
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.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Base class for distributed Tpetra objects that support data redistribution.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes which contain no entries in this object&#39;s Map.
virtual bool checkSizes(const SrcDistObject &source)=0
Compare the source and target (this) objects for compatibility.