Tpetra parallel linear algebra  Version of the Day
Tpetra_DistObjectKA_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_KA_DECL_HPP
43 #define TPETRA_DISTOBJECT_KA_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 #include <Kokkos_NodeAPIConfigDefs.hpp> // enum KokkosClassic::ReadWriteOption
51 
52 #if TPETRA_USE_KOKKOS_DISTOBJECT
53 
54 #include "KokkosCompat_View.hpp"
55 #include "Kokkos_Core.hpp"
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 
65 
66 namespace Tpetra {
75  template <class Packet,
76  class LocalOrdinal = Details::DefaultTypes::local_ordinal_type,
77  class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
79  class DistObjectKA :
80  virtual public SrcDistObject,
81  virtual public Teuchos::Describable {
82  public:
84 
85 
90  typedef Packet packet_type;
92  typedef LocalOrdinal local_ordinal_type;
94  typedef GlobalOrdinal global_ordinal_type;
96  typedef Node node_type;
97 
99  typedef typename Kokkos::Compat::NodeDevice<node_type>::type execution_space;
100  typedef typename execution_space::size_type view_size_type;
101 
103 
105 
107  explicit DistObjectKA (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& map);
108 
110  DistObjectKA (const DistObjectKA<Packet,LocalOrdinal,GlobalOrdinal,Node>& rhs);
111 
113  virtual ~DistObjectKA ();
114 
116 
118 
136  void
137  doImport (const SrcDistObject& source,
138  const Import<LocalOrdinal,GlobalOrdinal,Node>& importer,
139  CombineMode CM);
140 
158  void
159  doExport (const SrcDistObject& source,
160  const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter,
161  CombineMode CM);
162 
181  void
182  doImport (const SrcDistObject& source,
183  const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter,
184  CombineMode CM);
185 
204  void
205  doExport (const SrcDistObject& source,
206  const Import<LocalOrdinal,GlobalOrdinal,Node>& importer,
207  CombineMode CM);
208 
210 
212 
218  bool isDistributed () const;
219 
226  virtual Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
227  getMap() const { return map_; }
228 
230 
232 
237  void print (std::ostream &os) const;
238 
240 
242 
247  virtual std::string description () const;
248 
249 
254  virtual void
255  describe (Teuchos::FancyOStream &out,
256  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
258 
260 
306  virtual void
307  removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap);
308 
309  // Forward declaration of nonmember function.
310  template<class PT, class LO, class GO, class NT>
311  friend void
312  removeEmptyProcessesInPlace (Teuchos::RCP<Tpetra::DistObjectKA<PT, LO, GO, NT> >& input,
313  const Teuchos::RCP<const Map<LO, GO, NT> >& newMap);
314  // Forward declaration of nonmember function.
315  template<class PT, class LO, class GO, class NT>
316  friend void
317  removeEmptyProcessesInPlace (Teuchos::RCP<Tpetra::DistObjectKA<PT, LO, GO, NT> >& input);
319 
320  protected:
328  enum ReverseOption {
329  DoForward, //*!< Perform the transfer in forward mode.
330  DoReverse //*!< Perform the transfer in reverse mode.
331  };
332 
348  virtual size_t constantNumberOfPackets () const;
349 
372  virtual void
373  doTransfer (const SrcDistObject& src,
374  CombineMode CM,
375  size_t numSameIDs,
376  const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
377  const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs,
378  const Teuchos::ArrayView<const LocalOrdinal> &remoteLIDs,
379  const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
380  Distributor &distor,
381  ReverseOption revOp);
382 
393 
394 
398  virtual bool
399  checkSizes (const SrcDistObject& source) = 0;
400 
418  virtual void
419  copyAndPermute (
420  const SrcDistObject& source,
421  size_t numSameIDs,
422  const Kokkos::View<const LocalOrdinal*, execution_space> &permuteToLIDs,
423  const Kokkos::View<const LocalOrdinal*, execution_space> &permuteFromLIDs) = 0;
424 
447  virtual void
448  packAndPrepare (
449  const SrcDistObject& source,
450  const Kokkos::View<const LocalOrdinal*, execution_space> &exportLIDs,
451  Kokkos::View<Packet*, execution_space> &exports,
452  const Kokkos::View<size_t*, execution_space> &numPacketsPerLID,
453  size_t& constantNumPackets,
454  Distributor &distor) = 0;
455 
477  virtual void
478  unpackAndCombine (
479  const Kokkos::View<const LocalOrdinal*, execution_space> &importLIDs,
480  const Kokkos::View<const Packet*, execution_space> &imports,
481  const Kokkos::View<size_t*, execution_space> &numPacketsPerLID,
482  size_t constantNumPackets,
483  Distributor &distor,
484  CombineMode CM) = 0;
486 
493  virtual void createViews () const;
494 
510  virtual void createViewsNonConst (KokkosClassic::ReadWriteOption rwo);
511 
522  virtual void releaseViews () const;
523 
525  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > map_;
526 
527  private:
529  Kokkos::View<packet_type*,execution_space> imports_;
530 
541  Kokkos::View<size_t*,execution_space> numImportPacketsPerLID_;
542  typename Kokkos::View<size_t*,execution_space>::HostMirror host_numImportPacketsPerLID_;
543 
545  Kokkos::View<packet_type*,execution_space> exports_;
546 
557  Kokkos::View<size_t*,execution_space> numExportPacketsPerLID_;
558 
559 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
560  Teuchos::RCP<Teuchos::Time> doXferTimer_;
561  Teuchos::RCP<Teuchos::Time> copyAndPermuteTimer_;
562  Teuchos::RCP<Teuchos::Time> packAndPrepareTimer_;
563  Teuchos::RCP<Teuchos::Time> doPostsAndWaitsTimer_;
564  Teuchos::RCP<Teuchos::Time> unpackAndCombineTimer_;
565 #endif // HAVE_TPETRA_TRANSFER_TIMERS
566 
567  }; // class DistObject
568 
569 
652  template<class DistObjectType>
653  void
654  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
655  const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
656  typename DistObjectType::global_ordinal_type,
657  typename DistObjectType::node_type> >& newMap);
658 
695  template<class DistObjectType>
696  void
697  removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input);
698 
699 } // namespace Tpetra
700 
701 #endif /* TPETRA_USE_KOKKOS_DISTOBJECT */
702 
703 #endif /* TPETRA_DISTOBJECT_DECL_HPP */
Namespace Tpetra contains the class and methods constituting the Tpetra library.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
Abstract base class for sources of an Import or Export.
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&#39;s Map.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
CombineMode
Rule for combining data in an Import or Export.