Tpetra Matrix/Vector Services  Version of the Day
Tpetra_DistObject_decl.hpp
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 
45 #include "Tpetra_ConfigDefs.hpp"
46 #include "Tpetra_Map.hpp"
47 #include "Tpetra_Import.hpp"
48 #include "Tpetra_Export.hpp"
49 #include "Tpetra_SrcDistObject.hpp"
50 
51 // #ifndef HAVE_TPETRA_TRANSFER_TIMERS
52 // # define HAVE_TPETRA_TRANSFER_TIMERS 1
53 // #endif // HAVE_TPETRA_TRANSFER_TIMERS
54 
55 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
56 # undef HAVE_TPETRA_TRANSFER_TIMERS
57 #endif // HAVE_TPETRA_TRANSFER_TIMERS
58 
59 
60 namespace Tpetra {
168  template <class Packet,
169  class LocalOrdinal = int,
170  class GlobalOrdinal = LocalOrdinal,
171  class Node = Kokkos::DefaultNode::DefaultNodeType>
172  class DistObject :
173  virtual public SrcDistObject,
174  virtual public Teuchos::Describable {
175  public:
177 
178 
183  typedef Packet packet_type;
185  typedef LocalOrdinal local_ordinal_type;
187  typedef GlobalOrdinal global_ordinal_type;
189  typedef Node node_type;
190 
192 
194 
196  explicit DistObject (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& map);
197 
200 
202  virtual ~DistObject ();
203 
205 
207 
225  void
226  doImport (const SrcDistObject& source,
228  CombineMode CM);
229 
247  void
248  doExport (const SrcDistObject& source,
250  CombineMode CM);
251 
270  void
271  doImport (const SrcDistObject& source,
273  CombineMode CM);
274 
293  void
294  doExport (const SrcDistObject& source,
296  CombineMode CM);
297 
299 
301 
307  bool isDistributed () const;
308 
317  getMap() const { return map_; }
318 
320 
322 
327  void print (std::ostream &os) const;
328 
330 
332 
337  virtual std::string description () const;
338 
339 
344  virtual void
348 
350 
396  virtual void
398 
399  // Forward declaration of nonmember function.
400  template<class PT, class LO, class GO, class NT>
401  friend void
403  const Teuchos::RCP<const Map<LO, GO, NT> >& newMap);
404  // Forward declaration of nonmember function.
405  template<class PT, class LO, class GO, class NT>
406  friend void
409 
410  protected:
419  DoForward, //*!< Perform the transfer in forward mode.
420  DoReverse //*!< Perform the transfer in reverse mode.
421  };
422 
438  virtual size_t constantNumberOfPackets () const;
439 
462  virtual void
463  doTransfer (const SrcDistObject& src,
464  CombineMode CM,
465  size_t numSameIDs,
466  const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
467  const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs,
468  const Teuchos::ArrayView<const LocalOrdinal> &remoteLIDs,
469  const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
470  Distributor &distor,
471  ReverseOption revOp);
472 
483 
484 
488  virtual bool
489  checkSizes (const SrcDistObject& source) = 0;
490 
508  virtual void
509  copyAndPermute (const SrcDistObject& source,
510  size_t numSameIDs,
511  const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
512  const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs) = 0;
513 
536  virtual void
537  packAndPrepare (const SrcDistObject& source,
538  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
539  Teuchos::Array<Packet>& exports,
540  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
541  size_t& constantNumPackets,
542  Distributor &distor) = 0;
543 
565  virtual void
567  const Teuchos::ArrayView<const Packet> &imports,
568  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
569  size_t constantNumPackets,
570  Distributor &distor,
571  CombineMode CM) = 0;
573 
580  virtual void createViews () const;
581 
597  virtual void createViewsNonConst (Kokkos::ReadWriteOption rwo);
598 
609  virtual void releaseViews () const;
610 
613 
614  private:
616  Teuchos::Array<Packet> imports_;
617 
628  Teuchos::Array<size_t> numImportPacketsPerLID_;
629 
631  Teuchos::Array<Packet> exports_;
632 
643  Teuchos::Array<size_t> numExportPacketsPerLID_;
644 
645 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
646  Teuchos::RCP<Teuchos::Time> doXferTimer_;
647  Teuchos::RCP<Teuchos::Time> copyAndPermuteTimer_;
648  Teuchos::RCP<Teuchos::Time> packAndPrepareTimer_;
649  Teuchos::RCP<Teuchos::Time> doPostsAndWaitsTimer_;
650  Teuchos::RCP<Teuchos::Time> unpackAndCombineTimer_;
651 #endif // HAVE_TPETRA_TRANSFER_TIMERS
652  }; // class DistObject
653 
654 
737  template<class DistObjectType>
738  void
740  const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
741  typename DistObjectType::global_ordinal_type,
742  typename DistObjectType::node_type> >& newMap);
743 
780  template<class DistObjectType>
781  void
783 
784 } // namespace Tpetra
785 
786 #endif /* TPETRA_DISTOBJECT_DECL_HPP */
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
virtual void createViewsNonConst(Kokkos::ReadWriteOption rwo)
Hook for creating a nonconst view.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
virtual void packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< Packet > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)=0
Perform any packing or preparation required for communication.
virtual void createViews() const
Hook for creating a const view.
void print(std::ostream &os) const
Print this object to the given output stream.
Abstract base class for sources of an Import or Export.
bool isDistributed() const
Whether this is a globally distributed object.
virtual void releaseViews() const
Hook for releasing views.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
Remove processes which contain no elements in this object&#39;s Map.
GlobalOrdinal global_ordinal_type
The type of global indices.
DistObject(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Constructor.
virtual ~DistObject()
Destructor (virtual for memory safety of derived classes).
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getMap() const
The Map describing the parallel distribution of this object.
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs)=0
Perform copies and permutations that are local to this process.
Abstract base class for objects that can be the source of an Import or Export operation.
static const EVerbosityLevel verbLevel_default
Packet packet_type
The type of each datum being sent or received in an Import or Export.
virtual std::string description() const
One-line descriptiion of this object.
virtual size_t constantNumberOfPackets() const
Whether the implementation&#39;s instance promises always to have a constant number of packets per LID...
Node node_type
The Kokkos Node type.
LocalOrdinal local_ordinal_type
The type of local indices.
Describes a parallel distribution of objects over processes.
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.
void doImport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import data into this object using an Import object ("forward mode").
virtual void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const Packet > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode CM)=0
Perform any unpacking and combining after communication.
Base class for distributed Tpetra objects that support data redistribution.
void doExport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export data into this object using an Export object ("forward mode").
virtual void doTransfer(const SrcDistObject &src, CombineMode CM, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs, const Teuchos::ArrayView< const LocalOrdinal > &remoteLIDs, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Distributor &distor, ReverseOption revOp)
Redistribute data across memory images.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > map_
The Map over which this object is distributed.
virtual bool checkSizes(const SrcDistObject &source)=0
Compare the source and target (this) objects for compatibility.