Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Tpetra_DistObjectKA_decl.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //          Tpetra: Templated Linear Algebra Services Package
00005 //                 Copyright (2008) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 
00042 #ifndef TPETRA_DISTOBJECT_KA_DECL_HPP
00043 #define TPETRA_DISTOBJECT_KA_DECL_HPP
00044 
00045 #include "Tpetra_ConfigDefs.hpp"
00046 #include "Tpetra_Map.hpp"
00047 #include "Tpetra_Import.hpp"
00048 #include "Tpetra_Export.hpp"
00049 #include "Tpetra_SrcDistObject.hpp"
00050 
00051 #if TPETRA_USE_KOKKOS_DISTOBJECT
00052 
00053 #include "KokkosCompat_View.hpp"
00054 #include "Kokkos_Core.hpp"
00055 
00056 // #ifndef HAVE_TPETRA_TRANSFER_TIMERS
00057 // #  define HAVE_TPETRA_TRANSFER_TIMERS 1
00058 // #endif // HAVE_TPETRA_TRANSFER_TIMERS
00059 
00060 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
00061 #  undef HAVE_TPETRA_TRANSFER_TIMERS
00062 #endif // HAVE_TPETRA_TRANSFER_TIMERS
00063 
00064 
00065 namespace Tpetra {
00074   template <class Packet,
00075             class LocalOrdinal = Map<>::local_ordinal_type,
00076             class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
00077             class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
00078   class DistObjectKA :
00079     virtual public SrcDistObject,
00080     virtual public Teuchos::Describable {
00081   public:
00083 
00084 
00089     typedef Packet packet_type;
00091     typedef LocalOrdinal local_ordinal_type;
00093     typedef GlobalOrdinal global_ordinal_type;
00095     typedef Node node_type;
00096 
00098     typedef typename Kokkos::Compat::NodeDevice<node_type>::type device_type;
00099     typedef typename device_type::size_type view_size_type;
00100 
00102 
00103 
00104 
00106     explicit DistObjectKA (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& map);
00107 
00109     DistObjectKA (const DistObjectKA<Packet,LocalOrdinal,GlobalOrdinal,Node>& rhs);
00110 
00112     virtual ~DistObjectKA ();
00113 
00115 
00116 
00117 
00135     void
00136     doImport (const SrcDistObject& source,
00137               const Import<LocalOrdinal,GlobalOrdinal,Node>& importer,
00138               CombineMode CM);
00139 
00157     void
00158     doExport (const SrcDistObject& source,
00159               const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter,
00160               CombineMode CM);
00161 
00180     void
00181     doImport (const SrcDistObject& source,
00182               const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter,
00183               CombineMode CM);
00184 
00203     void
00204     doExport (const SrcDistObject& source,
00205               const Import<LocalOrdinal,GlobalOrdinal,Node>& importer,
00206               CombineMode CM);
00207 
00209 
00210 
00211 
00217     bool isDistributed () const;
00218 
00225     virtual Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
00226     getMap() const { return map_; }
00227 
00229 
00230 
00231 
00236     void print (std::ostream &os) const;
00237 
00239 
00240 
00241 
00246     virtual std::string description () const;
00247 
00248 
00253     virtual void
00254     describe (Teuchos::FancyOStream &out,
00255               const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00257 
00258 
00259 
00305     virtual void
00306     removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap);
00307 
00308     // Forward declaration of nonmember function.
00309     template<class PT, class LO, class GO, class NT>
00310     friend void
00311     removeEmptyProcessesInPlace (Teuchos::RCP<Tpetra::DistObjectKA<PT, LO, GO, NT> >& input,
00312                                  const Teuchos::RCP<const Map<LO, GO, NT> >& newMap);
00313     // Forward declaration of nonmember function.
00314     template<class PT, class LO, class GO, class NT>
00315     friend void
00316     removeEmptyProcessesInPlace (Teuchos::RCP<Tpetra::DistObjectKA<PT, LO, GO, NT> >& input);
00318 
00319   protected:
00327     enum ReverseOption {
00328       DoForward, //*!< Perform the transfer in forward mode.
00329       DoReverse  //*!< Perform the transfer in reverse mode.
00330     };
00331 
00347     virtual size_t constantNumberOfPackets () const;
00348 
00371     virtual void
00372     doTransfer (const SrcDistObject& src,
00373                 CombineMode CM,
00374                 size_t numSameIDs,
00375                 const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
00376                 const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs,
00377                 const Teuchos::ArrayView<const LocalOrdinal> &remoteLIDs,
00378                 const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
00379                 Distributor &distor,
00380                 ReverseOption revOp);
00381 
00392 
00393 
00397     virtual bool
00398     checkSizes (const SrcDistObject& source) = 0;
00399 
00417     virtual void
00418     copyAndPermute (
00419       const SrcDistObject& source,
00420       size_t numSameIDs,
00421       const Kokkos::View<const LocalOrdinal*, device_type> &permuteToLIDs,
00422       const Kokkos::View<const LocalOrdinal*, device_type> &permuteFromLIDs) = 0;
00423 
00446     virtual void
00447     packAndPrepare (
00448       const SrcDistObject& source,
00449       const Kokkos::View<const LocalOrdinal*, device_type> &exportLIDs,
00450       Kokkos::View<Packet*, device_type> &exports,
00451       const Kokkos::View<size_t*, device_type> &numPacketsPerLID,
00452       size_t& constantNumPackets,
00453       Distributor &distor) = 0;
00454 
00476     virtual void
00477     unpackAndCombine (
00478       const Kokkos::View<const LocalOrdinal*, device_type> &importLIDs,
00479       const Kokkos::View<const Packet*, device_type> &imports,
00480       const Kokkos::View<size_t*, device_type> &numPacketsPerLID,
00481       size_t constantNumPackets,
00482       Distributor &distor,
00483       CombineMode CM) = 0;
00485 
00492     virtual void createViews () const;
00493 
00509     virtual void createViewsNonConst (KokkosClassic::ReadWriteOption rwo);
00510 
00521     virtual void releaseViews () const;
00522 
00524     Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > map_;
00525 
00526   private:
00528     Kokkos::View<packet_type*,device_type> imports_;
00529 
00540     Kokkos::View<size_t*,device_type> numImportPacketsPerLID_;
00541     typename Kokkos::View<size_t*,device_type>::HostMirror host_numImportPacketsPerLID_;
00542 
00544     Kokkos::View<packet_type*,device_type> exports_;
00545 
00556     Kokkos::View<size_t*,device_type> numExportPacketsPerLID_;
00557 
00558 #ifdef HAVE_TPETRA_TRANSFER_TIMERS
00559     Teuchos::RCP<Teuchos::Time> doXferTimer_;
00560     Teuchos::RCP<Teuchos::Time> copyAndPermuteTimer_;
00561     Teuchos::RCP<Teuchos::Time> packAndPrepareTimer_;
00562     Teuchos::RCP<Teuchos::Time> doPostsAndWaitsTimer_;
00563     Teuchos::RCP<Teuchos::Time> unpackAndCombineTimer_;
00564 #endif // HAVE_TPETRA_TRANSFER_TIMERS
00565 
00566   }; // class DistObject
00567 
00568 
00651   template<class DistObjectType>
00652   void
00653   removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input,
00654                                const Teuchos::RCP<const Map<typename DistObjectType::local_ordinal_type,
00655                                                             typename DistObjectType::global_ordinal_type,
00656                                                             typename DistObjectType::node_type> >& newMap);
00657 
00694   template<class DistObjectType>
00695   void
00696   removeEmptyProcessesInPlace (Teuchos::RCP<DistObjectType>& input);
00697 
00698 } // namespace Tpetra
00699 
00700 #endif /* TPETRA_USE_KOKKOS_DISTOBJECT */
00701 
00702 #endif /* TPETRA_DISTOBJECT_DECL_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines