Tpetra Matrix/Vector Services Version of the Day
TpetraExt_MMHelpers_decl.hpp
Go to the documentation of this file.
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 
00043 #ifndef TPETRA_MMHELPERS_DECL_HPP
00044 #define TPETRA_MMHELPERS_DECL_HPP
00045 
00046 #include "Tpetra_ConfigDefs.hpp"
00047 #include "Teuchos_Array.hpp"
00048 #include <Kokkos_DefaultNode.hpp>
00049 #include <Kokkos_DefaultKernels.hpp>
00050 #include <set>
00051 #include <map>
00052 
00053 // Turn on to enable the special MMM timers
00054 // #define ENABLE_MMM_TIMINGS
00055 
00056 
00062 namespace Tpetra {
00063 #ifndef DOXYGEN_SHOULD_SKIP_THIS  
00064   // forward declaration
00065 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00066 class CrsMatrix;
00067 
00068 template <class LocalOrdinal, class GlobalOrdinal, class Node>
00069 class Map;
00070 #endif
00071 //struct that holds views of the contents of a CrsMatrix. These
00072 //contents may be a mixture of local and remote rows of the
00073 //actual matrix.
00074 template <class Scalar, 
00075   class LocalOrdinal=int, 
00076   class GlobalOrdinal=LocalOrdinal, 
00077   class Node=KokkosClassic::DefaultNode::DefaultNodeType, 
00078   class SpMatOps= typename KokkosClassic::DefaultKernels<Scalar, LocalOrdinal, Node>::SparseOps >
00079 class CrsMatrixStruct {
00080 public:
00081   CrsMatrixStruct();
00082 
00083   virtual ~CrsMatrixStruct();
00084 
00085   void deleteContents();
00086 
00087   //The maximum number of row entries a.k.a. the longest of the indice arrays.
00088   typename Array<ArrayView<const LocalOrdinal> >::size_type maxNumRowEntries;
00089   
00091   size_t numRows;
00093   Teuchos::Array<size_t> numEntriesPerRow;
00095   Teuchos::Array<Teuchos::ArrayView<const LocalOrdinal> > indices;
00097   Teuchos::Array<Teuchos::ArrayView<const Scalar> > values;
00099   Teuchos::Array<bool> remote;
00101   global_size_t numRemote;
00103   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > origRowMap;
00105   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > rowMap;
00107   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > colMap;
00109   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > domainMap;
00111   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > importColMap;
00113   Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps> >  importMatrix;  
00115   Teuchos::RCP<const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps> >  origMatrix;
00116   
00117 };
00118 
00119 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00120 int dumpCrsMatrixStruct(const CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps >& M);
00121 
00122 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00123 class CrsWrapper {
00124  public:
00125   virtual ~CrsWrapper(){}
00126 
00127   virtual Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const = 0;
00128 
00129   virtual bool isFillComplete() = 0;
00130 
00131   virtual void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values) = 0;
00132 
00133   virtual void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values) = 0;
00134 };
00135 
00136 template <class Scalar, 
00137   class LocalOrdinal=int, 
00138   class GlobalOrdinal=LocalOrdinal, 
00139   class Node=KokkosClassic::DefaultNode::DefaultNodeType, 
00140   class SpMatOps= typename KokkosClassic::DefaultKernels<Scalar, LocalOrdinal, Node>::SparseOps >
00141 class CrsWrapper_CrsMatrix : public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>{
00142  public:
00143   CrsWrapper_CrsMatrix(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps >& crsmatrix);
00144   virtual ~CrsWrapper_CrsMatrix();
00145 
00146   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const;
00147 
00148   bool isFillComplete();
00149 
00150   void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00151   void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00152 
00153  private:
00154   CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>& crsmat_;
00155 };
00156 
00157 template<class Scalar,
00158   class LocalOrdinal=int,
00159   class GlobalOrdinal=LocalOrdinal,
00160   class Node=KokkosClassic::DefaultNode::DefaultNodeType>
00161 class CrsWrapper_GraphBuilder : public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>{
00162  public:
00163   CrsWrapper_GraphBuilder(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map);
00164   virtual ~CrsWrapper_GraphBuilder();
00165 
00166   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {return rowmap_; }
00167 
00168   bool isFillComplete();
00169 
00170   void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00171   void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00172 
00173   std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>& get_graph();
00174 
00175   size_t get_max_row_length() { return max_row_length_; }
00176 
00177  private:
00178   std::map<GlobalOrdinal,std::set<GlobalOrdinal>*> graph_;
00179   const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowmap_;
00180   global_size_t max_row_length_;
00181 };
00182 
00183 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00184 void insert_matrix_locations(CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
00185                               CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>& C);
00186 
00187 
00188 
00189 }
00190 #endif // TPETRA_MMHELPERS_DECL_HPP
00191 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines