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 // #ifndef HAVE_TPETRA_TRANSFER_TIMERS
28 // # define HAVE_TPETRA_TRANSFER_TIMERS 1
29 // #endif // HAVE_TPETRA_TRANSFER_TIMERS
30 
31 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
32 # undef HAVE_TPETRA_TRANSFER_TIMERS
33 #endif // HAVE_TPETRA_TRANSFER_TIMERS
34 
35 namespace KokkosClassic {
40  enum ReadWriteOption {
41  ReadWrite = 0,
42  OverwriteAll = 1
43  };
44 } // namespace KokkosClassic
45 
46 namespace Tpetra {
47 
130  template<class DistObjectType>
131  void
132  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
133  const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
134  typename DistObjectType::global_ordinal_type,
135  typename DistObjectType::node_type> >& newMap);
136 
173  template<class DistObjectType>
174  void
175  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input);
176 
288  template <class Packet,
289  class LocalOrdinal,
290  class GlobalOrdinal,
291  class Node>
292  class DistObject :
293  virtual public SrcDistObject,
294  virtual public Teuchos::Describable
295  {
296  public:
298 
299 
304  using packet_type = typename ::Kokkos::ArithTraits<Packet>::val_type;
306  using local_ordinal_type = LocalOrdinal;
308  using global_ordinal_type = GlobalOrdinal;
310  using node_type = Node;
311 
313  using device_type = typename Node::device_type;
315  using execution_space = typename device_type::execution_space;
316 
319 
321 
323 
327  explicit DistObject (const Teuchos::RCP<const map_type>& map);
328 
331 
334 
337 
340 
350  virtual ~DistObject () = default;
351 
353 
355 
383  void
384  doImport (const SrcDistObject& source,
386  const CombineMode CM,
387  const bool restrictedMode = false);
388 
416  void
417  doExport (const SrcDistObject& source,
419  const CombineMode CM,
420  const bool restrictedMode = false);
421 
450  void
451  doImport (const SrcDistObject& source,
453  const CombineMode CM,
454  const bool restrictedMode = false);
455 
484  void
485  doExport (const SrcDistObject& source,
487  const CombineMode CM,
488  const bool restrictedMode = false);
489 
490  void
491  beginImport(const SrcDistObject& source,
493  const CombineMode CM,
494  const bool restrictedMode = false);
495 
496  void
497  beginExport(const SrcDistObject& source,
499  const CombineMode CM,
500  const bool restrictedMode = false);
501 
502  void
503  beginImport(const SrcDistObject& source,
505  const CombineMode CM,
506  const bool restrictedMode = false);
507 
508  void
509  beginExport(const SrcDistObject& source,
511  const CombineMode CM,
512  const bool restrictedMode = false);
513 
514  void
515  endImport(const SrcDistObject& source,
517  const CombineMode CM,
518  const bool restrictedMode = false);
519 
520  void
521  endExport(const SrcDistObject& source,
523  const CombineMode CM,
524  const bool restrictedMode = false);
525 
526  void
527  endImport(const SrcDistObject& source,
529  const CombineMode CM,
530  const bool restrictedMode = false);
531 
532  void
533  endExport(const SrcDistObject& source,
535  const CombineMode CM,
536  const bool restrictedMode = false);
537 
540  bool transferArrived() const;
541 
543 
545 
551  bool isDistributed () const;
552 
559  virtual Teuchos::RCP<const map_type> getMap () const { return map_; }
560 
562 
564 
569  void print (std::ostream& os) const;
570 
572 
574 
579  virtual std::string description () const;
580 
585  virtual void
586  describe (Teuchos::FancyOStream &out,
587  const Teuchos::EVerbosityLevel verbLevel =
588  Teuchos::Describable::verbLevel_default) const;
589 
591 
593 
640  virtual void
641  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
642 
644 
645  protected:
655  DoForward, //*!< Perform the transfer in forward mode.
656  DoReverse //*!< Perform the transfer in reverse mode.
657  };
658 
675  virtual size_t constantNumberOfPackets () const;
676 
696  virtual void
697  doTransfer (const SrcDistObject& src,
698  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
699  const char modeString[],
700  const ReverseOption revOp,
701  const CombineMode CM,
702  const bool restrictedMode);
703 
718  virtual bool
719  reallocArraysForNumPacketsPerLid (const size_t numExportLIDs,
720  const size_t numImportLIDs);
721 
722 
725  using buffer_memory_space =
726  ::Tpetra::Details::DefaultTypes::comm_buffer_memory_space<device_type>;
727 
728  public:
739  using buffer_device_type =
740  Kokkos::Device<typename device_type::execution_space,
742  protected:
748  void beginTransfer(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 endTransfer(const SrcDistObject& src,
756  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
757  const char modeString[],
758  const ReverseOption revOp,
759  const CombineMode CM,
760  const bool restrictedMode);
761 
762  void doPosts(const Details::DistributorPlan& distributorPlan,
763  size_t constantNumPackets,
764  bool commOnHost,
765  std::shared_ptr<std::string> prefix,
766  const bool canTryAliasing,
767  const CombineMode CM);
768 
769  void doPackAndPrepare(const SrcDistObject& src,
770  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
771  size_t& constantNumPackets,
772  const execution_space &space);
773 
774  void doUnpackAndCombine(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& remoteLIDs,
775  size_t constantNumPackets,
776  CombineMode CM,
777  const execution_space &space);
778 
789 
790 
794  virtual bool
795  checkSizes (const SrcDistObject& source) = 0;
796 
826  virtual void
827  copyAndPermute (const SrcDistObject& source,
828  const size_t numSameIDs,
829  const Kokkos::DualView<const local_ordinal_type*,
830  buffer_device_type>& permuteToLIDs,
831  const Kokkos::DualView<const local_ordinal_type*,
832  buffer_device_type>& permuteFromLIDs,
833  const CombineMode CM);
834 
835  // clang-format on
838  virtual void copyAndPermute(
839  const SrcDistObject &source, const size_t numSameIDs,
840  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
841  &permuteToLIDs,
842  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
843  &permuteFromLIDs,
844  const CombineMode CM, const execution_space &space);
845  // clang-format off
846 
884  virtual void
885  packAndPrepare (const SrcDistObject& source,
886  const Kokkos::DualView<const local_ordinal_type*,
887  buffer_device_type>& exportLIDs,
888  Kokkos::DualView<packet_type*,
889  buffer_device_type>& exports,
890  Kokkos::DualView<size_t*,
891  buffer_device_type> numPacketsPerLID,
892  size_t& constantNumPackets);
893 
896  virtual void
897  packAndPrepare (const SrcDistObject& source,
898  const Kokkos::DualView<const local_ordinal_type*,
899  buffer_device_type>& exportLIDs,
900  Kokkos::DualView<packet_type*,
901  buffer_device_type>& exports,
902  Kokkos::DualView<size_t*,
903  buffer_device_type> numPacketsPerLID,
904  size_t& constantNumPackets,
905  const execution_space &space);
906 
946  virtual void
947  unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
948  buffer_device_type>& importLIDs,
949  Kokkos::DualView<packet_type*,
950  buffer_device_type> imports,
951  Kokkos::DualView<size_t*,
952  buffer_device_type> numPacketsPerLID,
953  const size_t constantNumPackets,
954  const CombineMode combineMode);
955 
956  virtual void
957  unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
958  buffer_device_type>& importLIDs,
959  Kokkos::DualView<packet_type*,
960  buffer_device_type> imports,
961  Kokkos::DualView<size_t*,
962  buffer_device_type> numPacketsPerLID,
963  const size_t constantNumPackets,
964  const CombineMode combineMode,
965  const execution_space &space);
966 
968  Teuchos::RCP<const map_type> map_;
969 
970  protected:
971  std::unique_ptr<std::string>
972  createPrefix(const char className[],
973  const char methodName[]) const;
974 
981  Kokkos::DualView<packet_type*, buffer_device_type> imports_;
982 
1001  virtual bool
1002  reallocImportsIfNeeded (const size_t newSize,
1003  const bool verbose,
1004  const std::string* prefix,
1005  const bool remoteLIDsContiguous=false,
1006  const CombineMode CM=INSERT);
1007 
1021  Kokkos::DualView<size_t*, buffer_device_type> numImportPacketsPerLID_;
1022 
1028  Kokkos::DualView<packet_type*, buffer_device_type> exports_;
1029 
1043  Kokkos::DualView<size_t*, buffer_device_type> numExportPacketsPerLID_;
1044 
1045  private:
1047 
1048  Details::DistributorActor distributorActor_;
1049 
1050 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
1051  Teuchos::RCP<Teuchos::Time> doXferTimer_;
1052  Teuchos::RCP<Teuchos::Time> copyAndPermuteTimer_;
1053  Teuchos::RCP<Teuchos::Time> packAndPrepareTimer_;
1054  Teuchos::RCP<Teuchos::Time> doPostsAndWaitsTimer_;
1055  Teuchos::RCP<Teuchos::Time> unpackAndCombineTimer_;
1056 #endif // HAVE_TPETRA_TRANSFER_TIMERS
1057  }; // class DistObject
1058 } // namespace Tpetra
1059 
1060 #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.