Tpetra parallel linear algebra  Version of the Day
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 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_DISTOBJECT_DECL_HPP
43 #define TPETRA_DISTOBJECT_DECL_HPP
44 
52 
53 #include "Tpetra_Map.hpp"
54 #include "Tpetra_Import.hpp"
55 #include "Tpetra_Export.hpp"
56 #include "Tpetra_SrcDistObject.hpp"
58 #include "Kokkos_ArithTraits.hpp"
59 #include <type_traits>
60 
61 // #ifndef HAVE_TPETRA_TRANSFER_TIMERS
62 // # define HAVE_TPETRA_TRANSFER_TIMERS 1
63 // #endif // HAVE_TPETRA_TRANSFER_TIMERS
64 
65 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
66 # undef HAVE_TPETRA_TRANSFER_TIMERS
67 #endif // HAVE_TPETRA_TRANSFER_TIMERS
68 
69 namespace KokkosClassic {
75  ReadWrite = 0,
76  WriteOnly = 1
77  };
78 } // namespace KokkosClassic
79 
80 namespace Tpetra {
81 
164  template<class DistObjectType>
165  void
166  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
167  const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
168  typename DistObjectType::global_ordinal_type,
169  typename DistObjectType::node_type> >& newMap);
170 
207  template<class DistObjectType>
208  void
209  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input);
210 
211 namespace Classes {
212 
345  template <class Packet,
347  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
349  class DistObject :
350  virtual public SrcDistObject,
351  virtual public Teuchos::Describable
352  {
353  public:
355 
356 
361  typedef typename ::Kokkos::Details::ArithTraits<Packet>::val_type packet_type;
363  typedef LocalOrdinal local_ordinal_type;
365  typedef GlobalOrdinal global_ordinal_type;
367  typedef Node node_type;
368 
370  typedef typename Node::device_type device_type;
372  typedef typename device_type::execution_space execution_space;
373 
374  private:
375  typedef typename Kokkos::View<packet_type*, device_type>::size_type view_size_type;
377 
378  public:
381 
383 
385 
387  explicit DistObject (const Teuchos::RCP<const map_type>& map);
388 
391 
393  virtual ~DistObject ();
394 
396 
398 
417  void
418  doImport (const SrcDistObject& source,
420  CombineMode CM);
421 
440  void
441  doExport (const SrcDistObject& source,
443  CombineMode CM);
444 
464  void
465  doImport (const SrcDistObject& source,
467  CombineMode CM);
468 
488  void
489  doExport (const SrcDistObject& source,
491  CombineMode CM);
492 
494 
496 
502  bool isDistributed () const;
503 
510  virtual Teuchos::RCP<const map_type> getMap () const { return map_; }
511 
513 
515 
520  void print (std::ostream &os) const;
521 
523 
525 
530  virtual std::string description () const;
531 
536  virtual void
537  describe (Teuchos::FancyOStream &out,
538  const Teuchos::EVerbosityLevel verbLevel =
539  Teuchos::Describable::verbLevel_default) const;
540 
542 
544 
591  virtual void
592  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
593 
595 
596  protected:
606  DoForward, //*!< Perform the transfer in forward mode.
607  DoReverse //*!< Perform the transfer in reverse mode.
608  };
609 
626  virtual size_t constantNumberOfPackets () const;
627 
647  virtual void
648  doTransfer (const SrcDistObject& src,
649  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, node_type>& transfer,
650  const char modeString[],
651  const ReverseOption revOp,
652  const CombineMode CM);
653 
668  virtual bool
669  reallocArraysForNumPacketsPerLid (const size_t numExportLIDs,
670  const size_t numImportLIDs);
671 
672  virtual void
673  doTransferOld (const SrcDistObject& src,
674  CombineMode CM,
675  size_t numSameIDs,
676  const Teuchos::ArrayView<const local_ordinal_type> &permuteToLIDs,
677  const Teuchos::ArrayView<const local_ordinal_type> &permuteFromLIDs,
678  const Teuchos::ArrayView<const local_ordinal_type> &remoteLIDs,
679  const Teuchos::ArrayView<const local_ordinal_type> &exportLIDs,
680  Distributor &distor,
681  ReverseOption revOp);
682 
687 #ifdef KOKKOS_ENABLE_CUDA
688  typedef typename std::conditional<
689  std::is_same<typename device_type::execution_space, Kokkos::Cuda>::value,
690  Kokkos::CudaSpace,
691  typename device_type::memory_space>::type buffer_memory_space;
692 #else
693  typedef typename device_type::memory_space buffer_memory_space;
694 #endif // KOKKOS_ENABLE_CUDA
695 
696  public:
697 
708  typedef Kokkos::Device<
709  typename device_type::execution_space,
711 
712  protected:
713 
714  virtual void
715  doTransferNew (const SrcDistObject& src,
716  const CombineMode CM,
717  const size_t numSameIDs,
718  const Kokkos::DualView<const local_ordinal_type*,
719  device_type>& permuteToLIDs,
720  const Kokkos::DualView<const local_ordinal_type*,
721  device_type>& permuteFromLIDs,
722  const Kokkos::DualView<const local_ordinal_type*,
723  device_type>& remoteLIDs,
724  const Kokkos::DualView<const local_ordinal_type*,
725  device_type>& exportLIDs,
726  Distributor& distor,
727  const ReverseOption revOp,
728  const bool commOnHost);
729 
740 
741 
745  virtual bool
746  checkSizes (const SrcDistObject& source) = 0;
747 
761  virtual bool useNewInterface () { return false; }
762 
780  virtual void
782  size_t numSameIDs,
783  const Teuchos::ArrayView<const local_ordinal_type>& permuteToLIDs,
784  const Teuchos::ArrayView<const local_ordinal_type>& permuteFromLIDs)
785  {}
786  virtual void
787  copyAndPermuteNew (const SrcDistObject& source,
788  const size_t numSameIDs,
789  const Kokkos::DualView<const local_ordinal_type*, device_type>& permuteToLIDs,
790  const Kokkos::DualView<const local_ordinal_type*, device_type>& permuteFromLIDs)
791  {}
792 
815  virtual void
817  const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
818  Teuchos::Array<packet_type>& exports,
819  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
820  size_t& constantNumPackets,
821  Distributor &distor)
822  {}
823 
824  virtual void
825  packAndPrepareNew (const SrcDistObject& source,
826  const Kokkos::DualView<const local_ordinal_type*, device_type>& exportLIDs,
827  Kokkos::DualView<packet_type*, buffer_device_type>& exports,
828  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
829  size_t& constantNumPackets,
830  Distributor& distor)
831  {}
832 
856  virtual void
857  unpackAndCombine (const Teuchos::ArrayView<const local_ordinal_type>& importLIDs,
858  const Teuchos::ArrayView<const packet_type>& imports,
859  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
860  size_t constantNumPackets,
861  Distributor &distor,
862  CombineMode CM)
863  {}
864 
890  virtual void
891  unpackAndCombineNew (const Kokkos::DualView<const local_ordinal_type*, device_type>& importLIDs,
892  const Kokkos::DualView<const packet_type*, buffer_device_type>& imports,
893  const Kokkos::DualView<const size_t*, buffer_device_type>& numPacketsPerLID,
894  const size_t constantNumPackets,
895  Distributor& distor,
896  const CombineMode CM)
897  {}
899 
906  virtual void createViews () const;
907 
924 
939  virtual void releaseViews () const;
940 
942  Teuchos::RCP<const map_type> map_;
943 
944  protected:
951  Kokkos::DualView<packet_type*, buffer_device_type> imports_;
952 
967  bool
968  reallocImportsIfNeeded (const size_t newSize, const bool debug = false);
969 
983  Kokkos::DualView<size_t*, buffer_device_type> numImportPacketsPerLID_;
984 
990  Kokkos::DualView<packet_type*, buffer_device_type> exports_;
991 
1005  Kokkos::DualView<size_t*, buffer_device_type> numExportPacketsPerLID_;
1006 
1007 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
1008  private:
1009  Teuchos::RCP<Teuchos::Time> doXferTimer_;
1010  Teuchos::RCP<Teuchos::Time> copyAndPermuteTimer_;
1011  Teuchos::RCP<Teuchos::Time> packAndPrepareTimer_;
1012  Teuchos::RCP<Teuchos::Time> doPostsAndWaitsTimer_;
1013  Teuchos::RCP<Teuchos::Time> unpackAndCombineTimer_;
1014 #endif // HAVE_TPETRA_TRANSFER_TIMERS
1015 
1016  }; // class DistObject
1017 
1018 } // namespace Classes
1019 
1020 } // namespace Tpetra
1021 
1022 #endif // TPETRA_DISTOBJECT_DECL_HPP
Tpetra::Classes::DistObject::exports_
Kokkos::DualView< packet_type *, buffer_device_type > exports_
Buffer from which packed data are exported (sent to other processes).
Definition: Tpetra_DistObject_decl.hpp:990
Tpetra::Classes::DistObject::releaseViews
virtual void releaseViews() const
Hook for releasing views.
Definition: Tpetra_DistObject_def.hpp:1636
Tpetra::Classes::DistObject::removeEmptyProcessesInPlace
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes which contain no entries in this object's Map.
Definition: Tpetra_DistObject_def.hpp:214
Tpetra::Classes::DistObject::doTransfer
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)
Redistribute data across memory images.
Definition: Tpetra_DistObject_def.hpp:434
Tpetra::Classes::DistObject::local_ordinal_type
LocalOrdinal local_ordinal_type
The type of local indices.
Definition: Tpetra_DistObject_decl.hpp:363
Tpetra::Classes::DistObject::reallocImportsIfNeeded
bool reallocImportsIfNeeded(const size_t newSize, const bool debug=false)
Reallocate imports_ if needed.
Definition: Tpetra_DistObject_def.hpp:592
Tpetra::Classes::DistObject::map_
Teuchos::RCP< const map_type > map_
The Map over which this object is distributed.
Definition: Tpetra_DistObject_decl.hpp:942
Tpetra::Classes::DistObject::doImport
void doImport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import data into this object using an Import object ("forward mode").
Definition: Tpetra_DistObject_def.hpp:252
Tpetra::Classes::DistObject::reallocArraysForNumPacketsPerLid
virtual bool reallocArraysForNumPacketsPerLid(const size_t numExportLIDs, const size_t numImportLIDs)
Reallocate numExportPacketsPerLID_ and/or numImportPacketsPerLID_, if necessary.
Definition: Tpetra_DistObject_def.hpp:617
Tpetra::Details::DefaultTypes::node_type
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
Definition: Tpetra_Details_DefaultTypes.hpp:105
Tpetra::Classes::DistObject::packAndPrepare
virtual void packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const local_ordinal_type > &exportLIDs, Teuchos::Array< packet_type > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)
Perform any packing or preparation required for communication.
Definition: Tpetra_DistObject_decl.hpp:816
Tpetra_DistObject_fwd.hpp
Forward declaration of Tpetra::DistObject.
Tpetra::Classes::DistObject::device_type
Node::device_type device_type
The Kokkos Device type.
Definition: Tpetra_DistObject_decl.hpp:370
Tpetra::Classes::DistObject::buffer_memory_space
device_type::memory_space buffer_memory_space
Kokkos memory space for communication buffers.
Definition: Tpetra_DistObject_decl.hpp:693
Tpetra::Classes::DistObject::doExport
void doExport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export data into this object using an Export object ("forward mode").
Definition: Tpetra_DistObject_def.hpp:294
Tpetra::Classes::DistObject::getMap
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
Definition: Tpetra_DistObject_decl.hpp:510
Tpetra::Classes::DistObject::checkSizes
virtual bool checkSizes(const SrcDistObject &source)=0
Compare the source and target (this) objects for compatibility.
Tpetra::Classes::DistObject::description
virtual std::string description() const
One-line descriptiion of this object.
Definition: Tpetra_DistObject_def.hpp:127
Tpetra::Classes::DistObject::print
void print(std::ostream &os) const
Print this object to the given output stream.
Definition: Tpetra_DistObject_def.hpp:1609
Tpetra::Classes::DistObject::createViews
virtual void createViews() const
Hook for creating a const view.
Definition: Tpetra_DistObject_def.hpp:1624
Tpetra::Classes::DistObject
Base class for distributed Tpetra objects that support data redistribution.
Definition: Tpetra_DistObject_decl.hpp:349
Tpetra::Classes::DistObject< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node >::ReverseOption
ReverseOption
Whether the data transfer should be performed in forward or reverse mode.
Definition: Tpetra_DistObject_decl.hpp:605
Tpetra::Classes::DistObject::copyAndPermute
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const local_ordinal_type > &permuteToLIDs, const Teuchos::ArrayView< const local_ordinal_type > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
Definition: Tpetra_DistObject_decl.hpp:781
KokkosClassic::ReadWriteOption
ReadWriteOption
Read/write options for non-const views.
Definition: Tpetra_DistObject_decl.hpp:74
Tpetra::Classes::DistObject::~DistObject
virtual ~DistObject()
Destructor (virtual for memory safety of derived classes).
Definition: Tpetra_DistObject_def.hpp:121
Tpetra::Classes::Import
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Definition: Tpetra_Import_decl.hpp:115
Tpetra::Distributor
Sets up and executes a communication plan for a Tpetra DistObject.
Definition: Tpetra_Distributor.hpp:188
Tpetra::Classes::DistObject::imports_
Kokkos::DualView< packet_type *, buffer_device_type > imports_
Buffer into which packed data are imported (received from other processes).
Definition: Tpetra_DistObject_decl.hpp:951
Tpetra_SrcDistObject.hpp
Abstract base class for sources of an Import or Export.
Tpetra::Details::DefaultTypes::local_ordinal_type
int local_ordinal_type
Default value of Scalar template parameter.
Definition: Tpetra_Details_DefaultTypes.hpp:72
Tpetra::Classes::DistObject::unpackAndCombine
virtual void unpackAndCombine(const Teuchos::ArrayView< const local_ordinal_type > &importLIDs, const Teuchos::ArrayView< const packet_type > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode CM)
Perform any unpacking and combining after communication (old version that uses Teuchos memory managem...
Definition: Tpetra_DistObject_decl.hpp:857
Tpetra::removeEmptyProcessesInPlace
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.
Definition: Tpetra_DistObject_def.hpp:1643
Tpetra::Classes::DistObject::constantNumberOfPackets
virtual size_t constantNumberOfPackets() const
Whether the implementation's instance promises always to have a constant number of packets per LID (l...
Definition: Tpetra_DistObject_def.hpp:427
Tpetra::Classes::DistObject::map_type
Map< local_ordinal_type, global_ordinal_type, node_type > map_type
The type of the Map specialization to use with this class.
Definition: Tpetra_DistObject_decl.hpp:380
Tpetra::Classes::Map
A parallel distribution of indices over processes.
Definition: Tpetra_Map_decl.hpp:247
KokkosClassic::ReadWrite
Definition: Tpetra_DistObject_decl.hpp:75
Tpetra::Classes::DistObject::describe
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.
Definition: Tpetra_DistObject_def.hpp:147
Tpetra::Classes::DistObject::execution_space
device_type::execution_space execution_space
The Kokkos execution space.
Definition: Tpetra_DistObject_decl.hpp:372
Tpetra::Classes::DistObject::numImportPacketsPerLID_
Kokkos::DualView< size_t *, buffer_device_type > numImportPacketsPerLID_
Number of packets to receive for each receive operation.
Definition: Tpetra_DistObject_decl.hpp:983
Tpetra::Map
Classes::Map< LocalOrdinal, GlobalOrdinal, Node > Map
Alias for Tpetra::Classes::Map.
Definition: Tpetra_Map_fwd.hpp:71
Tpetra::Classes::DistObject::packet_type
::Kokkos::Details::ArithTraits< Packet >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
Definition: Tpetra_DistObject_decl.hpp:361
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
KokkosClassic::WriteOnly
Definition: Tpetra_DistObject_decl.hpp:76
Tpetra::Classes::DistObject::buffer_device_type
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Kokkos::Device specialization for communication buffers.
Definition: Tpetra_DistObject_decl.hpp:710
Tpetra::Classes::DistObject::useNewInterface
virtual bool useNewInterface()
Whether the subclass implements the "old" or "new" (Kokkos-friendly) interface.
Definition: Tpetra_DistObject_decl.hpp:761
Tpetra::Classes::Export
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Definition: Tpetra_Export_decl.hpp:124
Tpetra::Classes::DistObject::unpackAndCombineNew
virtual void unpackAndCombineNew(const Kokkos::DualView< const local_ordinal_type *, device_type > &importLIDs, const Kokkos::DualView< const packet_type *, buffer_device_type > &imports, const Kokkos::DualView< const size_t *, buffer_device_type > &numPacketsPerLID, const size_t constantNumPackets, Distributor &distor, const CombineMode CM)
Perform any unpacking and combining after communication (new version that uses Kokkos data structures...
Definition: Tpetra_DistObject_decl.hpp:891
Tpetra::SrcDistObject
Abstract base class for objects that can be the source of an Import or Export operation.
Definition: Tpetra_SrcDistObject.hpp:89
Tpetra::Classes::DistObject::createViewsNonConst
virtual void createViewsNonConst(KokkosClassic::ReadWriteOption rwo)
Hook for creating a nonconst view.
Definition: Tpetra_DistObject_def.hpp:1630
Tpetra::Classes::DistObject::numExportPacketsPerLID_
Kokkos::DualView< size_t *, buffer_device_type > numExportPacketsPerLID_
Number of packets to send for each send operation.
Definition: Tpetra_DistObject_decl.hpp:1005
Tpetra::Classes::DistObject::isDistributed
bool isDistributed() const
Whether this is a globally distributed object.
Definition: Tpetra_DistObject_def.hpp:420
Tpetra::Classes::DistObject::node_type
Node node_type
The Kokkos Node type.
Definition: Tpetra_DistObject_decl.hpp:367
Tpetra::Classes::DistObject::global_ordinal_type
GlobalOrdinal global_ordinal_type
The type of global indices.
Definition: Tpetra_DistObject_decl.hpp:365
Tpetra::CombineMode
CombineMode
Rule for combining data in an Import or Export.
Definition: Tpetra_CombineMode.hpp:94
Tpetra::Classes::DistObject::DistObject
DistObject(const Teuchos::RCP< const map_type > &map)
Constructor.
Definition: Tpetra_DistObject_def.hpp:63