Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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#ifndef TPETRA_DISTOBJECT_DECL_HPP
11#define TPETRA_DISTOBJECT_DECL_HPP
12
15
16#include "Tpetra_Details_DistributorActor.hpp"
17#include "Tpetra_Map.hpp"
18#include "Tpetra_Import.hpp"
19#include "Tpetra_Export.hpp"
22#include "KokkosKernels_ArithTraits.hpp"
23#include <memory>
24#include <type_traits>
25
26namespace KokkosClassic {
32 ReadWrite = 0,
33 OverwriteAll = 1
34};
35} // namespace KokkosClassic
36
37namespace Tpetra {
38
121template <class DistObjectType>
122void removeEmptyProcessesInPlace(Teuchos::RCP<DistObjectType>& input,
123 const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
124 typename DistObjectType::global_ordinal_type,
125 typename DistObjectType::node_type> >& newMap);
126
163template <class DistObjectType>
164void removeEmptyProcessesInPlace(Teuchos::RCP<DistObjectType>& input);
165
277template <class Packet,
278 class LocalOrdinal,
279 class GlobalOrdinal,
280 class Node>
281class DistObject : virtual public SrcDistObject,
282 virtual public Teuchos::Describable {
283 public:
285
286
291 using packet_type = typename ::KokkosKernels::ArithTraits<Packet>::val_type;
297 using node_type = Node;
298
300 using device_type = typename Node::device_type;
302 using execution_space = typename device_type::execution_space;
303
306
308
310
314 explicit DistObject(const Teuchos::RCP<const map_type>& map);
315
318
321
324
327
337 virtual ~DistObject() = default;
338
340
342
371 void
374 const CombineMode CM,
375 const bool restrictedMode = false);
376
405 void
408 const CombineMode CM,
409 const bool restrictedMode = false);
410
440 void
443 const CombineMode CM,
444 const bool restrictedMode = false);
445
475 void
478 const CombineMode CM,
479 const bool restrictedMode = false);
480
481 void
482 beginImport(const SrcDistObject& source,
484 const CombineMode CM,
485 const bool restrictedMode = false);
486
487 void
488 beginExport(const SrcDistObject& source,
490 const CombineMode CM,
491 const bool restrictedMode = false);
492
493 void
494 beginImport(const SrcDistObject& source,
496 const CombineMode CM,
497 const bool restrictedMode = false);
498
499 void
500 beginExport(const SrcDistObject& source,
502 const CombineMode CM,
503 const bool restrictedMode = false);
504
505 void
506 endImport(const SrcDistObject& source,
508 const CombineMode CM,
509 const bool restrictedMode = false);
510
511 void
512 endExport(const SrcDistObject& source,
514 const CombineMode CM,
515 const bool restrictedMode = false);
516
517 void
518 endImport(const SrcDistObject& source,
520 const CombineMode CM,
521 const bool restrictedMode = false);
522
523 void
524 endExport(const SrcDistObject& source,
526 const CombineMode CM,
527 const bool restrictedMode = false);
528
531 bool transferArrived() const;
532
534
536
542 bool isDistributed() const;
543
550 virtual Teuchos::RCP<const map_type> getMap() const { return map_; }
551
553
555
560 void print(std::ostream& os) const;
561
563
565
570 virtual std::string description() const;
571
576 virtual void
577 describe(Teuchos::FancyOStream& out,
578 const Teuchos::EVerbosityLevel verbLevel =
579 Teuchos::Describable::verbLevel_default) const;
580
582
584
626 virtual void
627 removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap);
628
630 const Details::DistributorActor& getActor() { return distributorActor_; }
631
633
634 protected:
644 DoForward, //*!< Perform the transfer in forward mode.
645 DoReverse //*!< Perform the transfer in reverse mode.
646 };
647
664 virtual size_t constantNumberOfPackets() const;
665
687 virtual void
688 doTransfer(const SrcDistObject& src,
689 const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
690 const char modeString[],
691 const ReverseOption revOp,
692 const CombineMode CM,
693 const bool restrictedMode);
694
709 virtual bool
711 const size_t numImportLIDs);
712
716 ::Tpetra::Details::DefaultTypes::comm_buffer_memory_space<device_type>;
717
718 public:
730 Kokkos::Device<typename device_type::execution_space,
732
733 protected:
739 void beginTransfer(const SrcDistObject& src,
740 const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
741 const char modeString[],
742 const ReverseOption revOp,
743 const CombineMode CM,
744 const bool restrictedMode);
745
746 void endTransfer(const SrcDistObject& src,
747 const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
748 const char modeString[],
749 const ReverseOption revOp,
750 const CombineMode CM,
751 const bool restrictedMode);
752
753 void doPostRecvs(const Details::DistributorPlan& distributorPlan,
754 size_t constantNumPackets,
755 bool commOnHost,
756 std::shared_ptr<std::string> prefix,
757 const bool canTryAliasing,
758 const CombineMode CM);
759
760 void doPostSends(const Details::DistributorPlan& distributorPlan,
761 size_t constantNumPackets,
762 bool commOnHost,
763 std::shared_ptr<std::string> prefix);
764
765 void doPackAndPrepare(const SrcDistObject& src,
766 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
767 size_t& constantNumPackets,
768 const execution_space& space);
769
770 void doUnpackAndCombine(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& remoteLIDs,
771 size_t constantNumPackets,
773 const execution_space& space);
774
785
786
790 virtual bool
792
822 virtual void
824 const size_t numSameIDs,
825 const Kokkos::DualView<const local_ordinal_type*,
827 const Kokkos::DualView<const local_ordinal_type*,
829 const CombineMode CM);
830
833 virtual void copyAndPermute(
834 const SrcDistObject& source, const size_t numSameIDs,
835 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
836 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
837 const CombineMode CM, const execution_space& space);
838
876 virtual void
878 const Kokkos::DualView<const local_ordinal_type*,
880 Kokkos::DualView<packet_type*,
881 buffer_device_type>& exports,
882 Kokkos::DualView<size_t*,
885 size_t& constantNumPackets);
886
889 virtual void
891 const Kokkos::DualView<const local_ordinal_type*,
893 Kokkos::DualView<packet_type*,
894 buffer_device_type>& exports,
895 Kokkos::DualView<size_t*,
898 size_t& constantNumPackets,
899 const execution_space& space);
900
940 virtual void
941 unpackAndCombine(const Kokkos::DualView<const local_ordinal_type*,
943 Kokkos::DualView<packet_type*,
945 imports,
946 Kokkos::DualView<size_t*,
949 const size_t constantNumPackets,
951
952 virtual void
953 unpackAndCombine(const Kokkos::DualView<const local_ordinal_type*,
955 Kokkos::DualView<packet_type*,
957 imports,
958 Kokkos::DualView<size_t*,
961 const size_t constantNumPackets,
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
ReadWriteOption
Read/write options for non-const views.
Forward declaration of Tpetra::DistObject.
Abstract base class for sources of an Import or Export.
Struct that holds views of the contents of a CrsMatrix.
Base class for distributed Tpetra objects that support data redistribution.
DistObject(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy constructor (default).
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.
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.
::Tpetra::Details::DefaultTypes::comm_buffer_memory_space< device_type > buffer_memory_space
Kokkos memory space for communication buffers.
DistObject(DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move constructor (default).
Kokkos::DualView< size_t *, buffer_device_type > numImportPacketsPerLID_
Number of packets to receive for each receive operation.
Kokkos::DualView< packet_type *, buffer_device_type > exports_
Buffer from which packed data are exported (sent to other processes).
Kokkos::DualView< packet_type *, buffer_device_type > imports_
Buffer into which packed data are imported (received from other processes).
virtual bool reallocArraysForNumPacketsPerLid(const size_t numExportLIDs, const size_t numImportLIDs)
Reallocate numExportPacketsPerLID_ and/or numImportPacketsPerLID_, if necessary.
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 ("forward mode").
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.
bool transferArrived() const
Whether the data from an import/export operation has arrived, and is ready for the unpack and combine...
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).
DistObject & operator=(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &)=default
Assignment operator (default).
DistObject & operator=(DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move assignment (default).
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Kokkos::Device specialization for communication buffers.
LocalOrdinal local_ordinal_type
The type of local indices.
typename Node::device_type device_type
The Kokkos Device type.
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.
virtual bool checkSizes(const SrcDistObject &source)=0
Compare the source and target (this) objects for compatibility.
typename device_type::execution_space execution_space
The Kokkos execution space.
void print(std::ostream &os) const
Print this object to the given output stream.
GlobalOrdinal global_ordinal_type
The type of global indices.
Kokkos::DualView< size_t *, buffer_device_type > numExportPacketsPerLID_
Number of packets to send for each send operation.
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 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.
Teuchos::RCP< const map_type > map_
The Map over which this object is distributed.
ReverseOption
Whether the data transfer should be performed in forward or reverse mode.
Node node_type
The Node type. If you don't know what this is, don't use it.
const Details::DistributorActor & getActor()
Getter for the DistributorActor.
virtual size_t constantNumberOfPackets() const
Whether the implementation's instance promises always to have a constant number of packets per LID (l...
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 ("forward mode").
virtual std::string description() const
One-line descriptiion of this object.
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
virtual ~DistObject()=default
Destructor (virtual for memory safety of derived classes).
typename ::KokkosKernels::ArithTraits< Packet >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes which contain no entries in this object's Map.
bool isDistributed() const
Whether this is a globally distributed object.
A parallel distribution of indices over processes.
Abstract base class for objects that can be the source of an Import or Export operation.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
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.
CombineMode
Rule for combining data in an Import or Export.
@ INSERT
Insert new values that don't currently exist.