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//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// ************************************************************************
38// @HEADER
39
40// clang-format off
41#ifndef TPETRA_DISTOBJECT_DECL_HPP
42#define TPETRA_DISTOBJECT_DECL_HPP
43
46
47#include "Tpetra_Details_DistributorActor.hpp"
48#include "Tpetra_Map.hpp"
49#include "Tpetra_Import.hpp"
50#include "Tpetra_Export.hpp"
53#include "Kokkos_ArithTraits.hpp"
54#include <memory>
55#include <type_traits>
56
57// #ifndef HAVE_TPETRA_TRANSFER_TIMERS
58// # define HAVE_TPETRA_TRANSFER_TIMERS 1
59// #endif // HAVE_TPETRA_TRANSFER_TIMERS
60
61#ifdef HAVE_TPETRA_TRANSFER_TIMERS
62# undef HAVE_TPETRA_TRANSFER_TIMERS
63#endif // HAVE_TPETRA_TRANSFER_TIMERS
64
65namespace KokkosClassic {
74} // namespace KokkosClassic
75
76namespace Tpetra {
77
160 template<class DistObjectType>
161 void
162 removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
163 const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
164 typename DistObjectType::global_ordinal_type,
165 typename DistObjectType::node_type> >& newMap);
166
203 template<class DistObjectType>
204 void
205 removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input);
206
318 template <class Packet,
319 class LocalOrdinal,
320 class GlobalOrdinal,
321 class Node>
323 virtual public SrcDistObject,
324 virtual public Teuchos::Describable
325 {
326 public:
328
329
334 using packet_type = typename ::Kokkos::ArithTraits<Packet>::val_type;
336 using local_ordinal_type = LocalOrdinal;
338 using global_ordinal_type = GlobalOrdinal;
340 using node_type = Node;
341
343 using device_type = typename Node::device_type;
345 using execution_space = typename device_type::execution_space;
346
349
351
353
357 explicit DistObject (const Teuchos::RCP<const map_type>& map);
358
361
364
367
370
380 virtual ~DistObject () = default;
381
383
385
413 void
414 doImport (const SrcDistObject& source,
416 const CombineMode CM,
417 const bool restrictedMode = false);
418
446 void
447 doExport (const SrcDistObject& source,
449 const CombineMode CM,
450 const bool restrictedMode = false);
451
480 void
481 doImport (const SrcDistObject& source,
483 const CombineMode CM,
484 const bool restrictedMode = false);
485
514 void
515 doExport (const SrcDistObject& source,
517 const CombineMode CM,
518 const bool restrictedMode = false);
519
520 void
521 beginImport(const SrcDistObject& source,
523 const CombineMode CM,
524 const bool restrictedMode = false);
525
526 void
527 beginExport(const SrcDistObject& source,
529 const CombineMode CM,
530 const bool restrictedMode = false);
531
532 void
533 beginImport(const SrcDistObject& source,
535 const CombineMode CM,
536 const bool restrictedMode = false);
537
538 void
539 beginExport(const SrcDistObject& source,
541 const CombineMode CM,
542 const bool restrictedMode = false);
543
544 void
545 endImport(const SrcDistObject& source,
547 const CombineMode CM,
548 const bool restrictedMode = false);
549
550 void
551 endExport(const SrcDistObject& source,
553 const CombineMode CM,
554 const bool restrictedMode = false);
555
556 void
557 endImport(const SrcDistObject& source,
559 const CombineMode CM,
560 const bool restrictedMode = false);
561
562 void
563 endExport(const SrcDistObject& source,
565 const CombineMode CM,
566 const bool restrictedMode = false);
567
570 bool transferArrived() const;
571
573
575
581 bool isDistributed () const;
582
589 virtual Teuchos::RCP<const map_type> getMap () const { return map_; }
590
592
594
599 void print (std::ostream& os) const;
600
602
604
609 virtual std::string description () const;
610
615 virtual void
616 describe (Teuchos::FancyOStream &out,
617 const Teuchos::EVerbosityLevel verbLevel =
618 Teuchos::Describable::verbLevel_default) const;
619
621
623
670 virtual void
671 removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
672
674
675 protected:
685 DoForward, //*!< Perform the transfer in forward mode.
686 DoReverse //*!< Perform the transfer in reverse mode.
687 };
688
705 virtual size_t constantNumberOfPackets () const;
706
726 virtual void
728 const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
729 const char modeString[],
730 const ReverseOption revOp,
731 const CombineMode CM,
732 const bool restrictedMode);
733
748 virtual bool
749 reallocArraysForNumPacketsPerLid (const size_t numExportLIDs,
750 const size_t numImportLIDs);
751
752
756 ::Tpetra::Details::DefaultTypes::comm_buffer_memory_space<device_type>;
757
758 public:
770 Kokkos::Device<typename device_type::execution_space,
772 protected:
779 const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
780 const char modeString[],
781 const ReverseOption revOp,
782 const CombineMode CM,
783 const bool restrictedMode);
784
785 void endTransfer(const SrcDistObject& src,
786 const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
787 const char modeString[],
788 const ReverseOption revOp,
789 const CombineMode CM,
790 const bool restrictedMode);
791
792 void doPosts(const Details::DistributorPlan& distributorPlan,
793 size_t constantNumPackets,
794 bool commOnHost,
795 std::shared_ptr<std::string> prefix,
796 const bool canTryAliasing,
797 const CombineMode CM);
798
799 void doPackAndPrepare(const SrcDistObject& src,
800 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
801 size_t& constantNumPackets,
802 const execution_space &space);
803
804 void doUnpackAndCombine(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& remoteLIDs,
805 size_t constantNumPackets,
806 CombineMode CM,
807 const execution_space &space);
808
819
820
824 virtual bool
825 checkSizes (const SrcDistObject& source) = 0;
826
856 virtual void
858 const size_t numSameIDs,
859 const Kokkos::DualView<const local_ordinal_type*,
860 buffer_device_type>& permuteToLIDs,
861 const Kokkos::DualView<const local_ordinal_type*,
862 buffer_device_type>& permuteFromLIDs,
863 const CombineMode CM);
864
865 // clang-format on
868 virtual void copyAndPermute(
869 const SrcDistObject &source, const size_t numSameIDs,
870 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
871 &permuteToLIDs,
872 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
873 &permuteFromLIDs,
874 const CombineMode CM, const execution_space &space);
875 // clang-format off
876
914 virtual void
916 const Kokkos::DualView<const local_ordinal_type*,
917 buffer_device_type>& exportLIDs,
918 Kokkos::DualView<packet_type*,
919 buffer_device_type>& exports,
920 Kokkos::DualView<size_t*,
921 buffer_device_type> numPacketsPerLID,
922 size_t& constantNumPackets);
923
926 virtual void
928 const Kokkos::DualView<const local_ordinal_type*,
929 buffer_device_type>& exportLIDs,
930 Kokkos::DualView<packet_type*,
931 buffer_device_type>& exports,
932 Kokkos::DualView<size_t*,
933 buffer_device_type> numPacketsPerLID,
934 size_t& constantNumPackets,
935 const execution_space &space);
936
976 virtual void
977 unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
978 buffer_device_type>& importLIDs,
979 Kokkos::DualView<packet_type*,
980 buffer_device_type> imports,
981 Kokkos::DualView<size_t*,
982 buffer_device_type> numPacketsPerLID,
983 const size_t constantNumPackets,
984 const CombineMode combineMode);
985
986 virtual void
987 unpackAndCombine (const Kokkos::DualView<const local_ordinal_type*,
988 buffer_device_type>& importLIDs,
989 Kokkos::DualView<packet_type*,
990 buffer_device_type> imports,
991 Kokkos::DualView<size_t*,
992 buffer_device_type> numPacketsPerLID,
993 const size_t constantNumPackets,
994 const CombineMode combineMode,
995 const execution_space &space);
996
998 Teuchos::RCP<const map_type> map_;
999
1000 protected:
1001 std::unique_ptr<std::string>
1002 createPrefix(const char className[],
1003 const char methodName[]) const;
1004
1011 Kokkos::DualView<packet_type*, buffer_device_type> imports_;
1012
1031 virtual bool
1032 reallocImportsIfNeeded (const size_t newSize,
1033 const bool verbose,
1034 const std::string* prefix,
1035 const bool remoteLIDsContiguous=false,
1036 const CombineMode CM=INSERT);
1037
1051 Kokkos::DualView<size_t*, buffer_device_type> numImportPacketsPerLID_;
1052
1058 Kokkos::DualView<packet_type*, buffer_device_type> exports_;
1059
1073 Kokkos::DualView<size_t*, buffer_device_type> numExportPacketsPerLID_;
1074
1075 private:
1077
1078 Details::DistributorActor distributorActor_;
1079
1080#ifdef HAVE_TPETRA_TRANSFER_TIMERS
1081 Teuchos::RCP<Teuchos::Time> doXferTimer_;
1082 Teuchos::RCP<Teuchos::Time> copyAndPermuteTimer_;
1083 Teuchos::RCP<Teuchos::Time> packAndPrepareTimer_;
1084 Teuchos::RCP<Teuchos::Time> doPostsAndWaitsTimer_;
1085 Teuchos::RCP<Teuchos::Time> unpackAndCombineTimer_;
1086#endif // HAVE_TPETRA_TRANSFER_TIMERS
1087 }; // class DistObject
1088} // namespace Tpetra
1089
1090#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.
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.
void doImport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const CombineMode CM, const bool restrictedMode=false)
Import data into this object using an Export object ("reverse mode").
DistObject(DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move constructor (default).
Kokkos::DualView< size_t *, buffer_device_type > numImportPacketsPerLID_
Kokkos::DualView< packet_type *, buffer_device_type > exports_
Kokkos::DualView< packet_type *, buffer_device_type > imports_
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.
DistObject(const Teuchos::RCP< const map_type > &map)
Constructor.
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, const execution_space &space)
Same as copyAndPermute, but do operations in space.
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).
::Tpetra::Details::DefaultTypes::comm_buffer_memory_space< device_type > buffer_memory_space
DistObject & operator=(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &)=default
Assignment operator (default).
void doExport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const CombineMode CM, const bool restrictedMode=false)
Export data into this object using an Import object ("reverse mode").
Map< local_ordinal_type, global_ordinal_type, node_type > map_type
typename ::Kokkos::ArithTraits< char >::val_type packet_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
void print(std::ostream &os) const
Print this object to the given output stream.
Kokkos::DualView< size_t *, buffer_device_type > numExportPacketsPerLID_
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.
ReverseOption
Whether the data transfer should be performed in forward or reverse mode.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
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.
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, const execution_space &space)
Same as packAndPrepare, but in an execution space instance.
bool isDistributed() const
Whether this is a globally distributed object.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
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.