Tpetra Matrix/Vector Services Version of the Day
TpetraExt_MMHelpers_decl.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Tpetra: Templated Linear Algebra Services Package 
00005 //                 Copyright (2008) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ************************************************************************
00027 //@HEADER
00028 
00029 
00030 #ifndef TPETRA_MMHELPERS_DECL_HPP
00031 #define TPETRA_MMHELPERS_DECL_HPP
00032 
00033 #include "Tpetra_ConfigDefs.hpp"
00034 #include "Teuchos_Array.hpp"
00035 #include <Kokkos_DefaultNode.hpp>
00036 #include <Kokkos_DefaultKernels.hpp>
00037 #include <set>
00038 #include <map>
00039 
00040 
00046 namespace Tpetra {
00047 #ifndef DOXYGEN_SHOULD_SKIP_THIS  
00048   // forward declaration
00049 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00050 class CrsMatrix;
00051 
00052 template <class LocalOrdinal, class GlobalOrdinal, class Node>
00053 class Map;
00054 #endif
00055 //struct that holds views of the contents of a CrsMatrix. These
00056 //contents may be a mixture of local and remote rows of the
00057 //actual matrix.
00058 template <class Scalar, 
00059   class LocalOrdinal=int, 
00060   class GlobalOrdinal=LocalOrdinal, 
00061   class Node=Kokkos::DefaultNode::DefaultNodeType, 
00062   class SpMatOps= typename Kokkos::DefaultKernels<Scalar, LocalOrdinal, Node>::SparseOps >
00063 class CrsMatrixStruct {
00064 public:
00065   CrsMatrixStruct();
00066 
00067   virtual ~CrsMatrixStruct();
00068 
00069   void deleteContents();
00070 
00071   //The maximum number of row entries a.k.a. the longest of the indice arrays.
00072   typename Array<ArrayView<const LocalOrdinal> >::size_type maxNumRowEntries;
00073   
00075   size_t numRows;
00077   Teuchos::Array<size_t> numEntriesPerRow;
00079   Teuchos::Array<Teuchos::ArrayView<const LocalOrdinal> > indices;
00081   Teuchos::Array<Teuchos::ArrayView<const Scalar> > values;
00083   Teuchos::Array<bool> remote;
00085   global_size_t numRemote;
00087   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > origRowMap;
00089   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > rowMap;
00091   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > colMap;
00093   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > domainMap;
00095   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > importColMap;
00097   Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps> >  importMatrix;
00098 };
00099 
00100 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00101 int dumpCrsMatrixStruct(const CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps >& M);
00102 
00103 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00104 class CrsWrapper {
00105  public:
00106   virtual ~CrsWrapper(){}
00107 
00108   virtual Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const = 0;
00109 
00110   virtual bool isFillComplete() = 0;
00111 
00112   virtual void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values) = 0;
00113 
00114   virtual void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values) = 0;
00115 };
00116 
00117 template <class Scalar, 
00118   class LocalOrdinal=int, 
00119   class GlobalOrdinal=LocalOrdinal, 
00120   class Node=Kokkos::DefaultNode::DefaultNodeType, 
00121   class SpMatOps= typename Kokkos::DefaultKernels<Scalar, LocalOrdinal, Node>::SparseOps >
00122 class CrsWrapper_CrsMatrix : public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>{
00123  public:
00124   CrsWrapper_CrsMatrix(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps >& crsmatrix);
00125   virtual ~CrsWrapper_CrsMatrix();
00126 
00127   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const;
00128 
00129   bool isFillComplete();
00130 
00131   void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00132   void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00133 
00134  private:
00135   CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>& crsmat_;
00136 };
00137 
00138 template<class Scalar,
00139   class LocalOrdinal=int,
00140   class GlobalOrdinal=LocalOrdinal,
00141   class Node=Kokkos::DefaultNode::DefaultNodeType>
00142 class CrsWrapper_GraphBuilder : public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>{
00143  public:
00144   CrsWrapper_GraphBuilder(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map);
00145   virtual ~CrsWrapper_GraphBuilder();
00146 
00147   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {return rowmap_; }
00148 
00149   bool isFillComplete();
00150 
00151   void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00152   void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
00153 
00154   std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>& get_graph();
00155 
00156   size_t get_max_row_length() { return max_row_length_; }
00157 
00158  private:
00159   std::map<GlobalOrdinal,std::set<GlobalOrdinal>*> graph_;
00160   const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowmap_;
00161   global_size_t max_row_length_;
00162 };
00163 
00164 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00165 void insert_matrix_locations(CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
00166                               CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>& C);
00167 
00168 
00169 
00170 }
00171 #endif // TPETRA_MMHELPERS_DECL_HPP
00172 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines