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// 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"
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
35namespace KokkosClassic {
41 ReadWrite = 0,
42 OverwriteAll = 1
43 };
44} // namespace KokkosClassic
45
46namespace 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>
293 virtual public SrcDistObject,
294 virtual public Teuchos::Describable
295 {
296 public:
298
299
304 using packet_type = typename ::Kokkos::ArithTraits<Packet>::val_type;
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
386 const CombineMode CM,
387 const bool restrictedMode = false);
388
416 void
419 const CombineMode CM,
420 const bool restrictedMode = false);
421
450 void
453 const CombineMode CM,
454 const bool restrictedMode = false);
455
484 void
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
720 const size_t numImportLIDs);
721
722
726 ::Tpetra::Details::DefaultTypes::comm_buffer_memory_space<device_type>;
727
728 public:
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,
777 const execution_space &space);
778
789
790
794 virtual bool
796
826 virtual void
828 const size_t numSameIDs,
829 const Kokkos::DualView<const local_ordinal_type*,
831 const Kokkos::DualView<const local_ordinal_type*,
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>
842 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
844 const CombineMode CM, const execution_space &space);
845 // clang-format off
846
884 virtual void
886 const Kokkos::DualView<const local_ordinal_type*,
888 Kokkos::DualView<packet_type*,
889 buffer_device_type>& exports,
890 Kokkos::DualView<size_t*,
892 size_t& constantNumPackets);
893
896 virtual void
898 const Kokkos::DualView<const local_ordinal_type*,
900 Kokkos::DualView<packet_type*,
901 buffer_device_type>& exports,
902 Kokkos::DualView<size_t*,
904 size_t& constantNumPackets,
905 const execution_space &space);
906
946 virtual void
947 unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
949 Kokkos::DualView<packet_type*,
950 buffer_device_type> imports,
951 Kokkos::DualView<size_t*,
953 const size_t constantNumPackets,
955
956 virtual void
957 unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
959 Kokkos::DualView<packet_type*,
960 buffer_device_type> imports,
961 Kokkos::DualView<size_t*,
963 const size_t constantNumPackets,
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
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).
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.
typename ::Kokkos::ArithTraits< Packet >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
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.
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).
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.