Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_VbrMatrix.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2009) 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 #ifndef KOKKOS_VBRMATRIX_HPP
00030 #define KOKKOS_VBRMATRIX_HPP
00031 
00032 #include <Teuchos_RCP.hpp>
00033 #include <Teuchos_TypeNameTraits.hpp>
00034 #include <Teuchos_TestForException.hpp>
00035 #include <Teuchos_ArrayRCP.hpp>
00036 
00037 #include "Kokkos_ConfigDefs.hpp"
00038 #include "Kokkos_DefaultNode.hpp"
00039 
00040 namespace Kokkos {
00041 
00043 
00044   template <class Scalar, class Ordinal, class Node = DefaultNode::DefaultNodeType>
00045   class VbrMatrix {
00046   public:
00047 
00048     typedef Scalar  ScalarType;
00049     typedef Ordinal OrdinalType;
00050     typedef Node    NodeType;
00051 
00053 
00054 
00056     VbrMatrix(size_t numBlockRows, const RCP<Node> &node = DefaultNode::getDefaultNode());
00057 
00059     ~VbrMatrix();
00060 
00062 
00064 
00065     
00067     RCP<Node> getNode() const;
00068 
00070 
00072 
00073 
00075     void setPackedValues(const ArrayRCP<const Scalar>& allvals,
00076                          const ArrayRCP<const Ordinal>& rptr,
00077                          const ArrayRCP<const Ordinal>& cptr,
00078                          const ArrayRCP<const size_t>& bptr,
00079                          const ArrayRCP<const Ordinal>& bindx,
00080                          const ArrayRCP<const Ordinal>& indx);
00081 
00083     void setBlockRow(size_t row, const ArrayRCP<ArrayRCP<const Scalar> > &blockEntry);
00084 
00086     bool isPacked() const;
00087   
00089     bool isEmpty() const;
00090 
00092     size_t getNumBlockRows() const;
00093 
00095     void clear();
00096 
00097     const ArrayRCP<const Scalar>& get_values() const { return pbuf_values1D_; }
00098     const ArrayRCP<const Ordinal>& get_rptr() const { return pbuf_rptr_; }
00099     const ArrayRCP<const Ordinal>& get_cptr() const { return pbuf_cptr_; }
00100     const ArrayRCP<const size_t>& get_bptr() const { return pbuf_bptr_; }
00101     const ArrayRCP<const Ordinal>& get_bindx() const { return pbuf_bindx_; }
00102     const ArrayRCP<const Ordinal>& get_indx() const { return pbuf_indx_; }
00103 
00105 
00106   private:
00108     VbrMatrix(const VbrMatrix& source);
00109 
00110     RCP<Node> node_;
00111     size_t numRows_;
00112     bool isInitialized_, isPacked_, isEmpty_;
00113 
00114     ArrayRCP<const Scalar> pbuf_values1D_;
00115     ArrayRCP<const Ordinal> pbuf_rptr_;
00116     ArrayRCP<const Ordinal> pbuf_cptr_;
00117     ArrayRCP<const size_t> pbuf_bptr_;
00118     ArrayRCP<const Ordinal> pbuf_bindx_;
00119     ArrayRCP<const Ordinal> pbuf_indx_;
00120     
00121     //Logically/mathematically, each block-entry is a dense matrix (a rectangular
00122     //array).
00123     //In keeping with the tradition of Aztec's DVBR and Epetra_VbrMatrix, each block-entry
00124     //is assumed to be stored in column-major order. I.e., the scalars for a given
00125     //column of the block-entry are stored consecutively (in contiguous memory).
00126   };
00127 
00128 
00129   //==============================================================================
00130   template <class Scalar, class Ordinal, class Node>
00131   VbrMatrix<Scalar,Ordinal,Node>::VbrMatrix(size_t numRows, const RCP<Node> &node)
00132   : node_(node)
00133   , numRows_(numRows)
00134   , isInitialized_(false)
00135   , isPacked_(false)
00136   , isEmpty_(true) {
00137   }
00138 
00139   //==============================================================================
00140   template <class Scalar, class Ordinal, class Node>
00141   VbrMatrix<Scalar,Ordinal,Node>::~VbrMatrix() {
00142   }
00143 
00144   //==============================================================================
00145   template <class Scalar, class Ordinal, class Node>
00146   RCP<Node> VbrMatrix<Scalar,Ordinal,Node>::getNode() const {
00147     return node_;
00148   }
00149 
00150   //==============================================================================
00151   template <class Scalar, class Ordinal, class Node>
00152   void VbrMatrix<Scalar,Ordinal,Node>::clear() { 
00153     pbuf_values1D_ = null;
00154     pbuf_rptr_ = null;
00155     pbuf_cptr_ = null;
00156     pbuf_bptr_ = null;
00157     pbuf_bindx_ = null;
00158     pbuf_indx_ = null;
00159     isInitialized_ = false;
00160     isEmpty_       = true;
00161     isPacked_      = false;
00162   }
00163 
00164   //==============================================================================
00165   template <class Scalar, class Ordinal, class Node>
00166   void VbrMatrix<Scalar,Ordinal,Node>::setPackedValues(
00167                         const ArrayRCP<const Scalar> &allvals,
00168                          const ArrayRCP<const Ordinal>& rptr,
00169                          const ArrayRCP<const Ordinal>& cptr,
00170                          const ArrayRCP<const size_t>& bptr,
00171                          const ArrayRCP<const Ordinal>& bindx,
00172                          const ArrayRCP<const Ordinal>& indx)
00173 {
00174 #ifdef HAVE_KOKKOS_DEBUG
00175     TEST_FOR_EXCEPTION(isInitialized_ == true, std::runtime_error,
00176         Teuchos::typeName(*this) << "::setPackedValues(): matrix is already initialized. Call clear() before reinitializing.");
00177 #endif
00178     isEmpty_ = (allvals == null);
00179     pbuf_values1D_ = allvals;
00180     pbuf_rptr_ = rptr;
00181     pbuf_cptr_ = cptr;
00182     pbuf_bptr_ = bptr;
00183     pbuf_bindx_ = bindx;
00184     pbuf_indx_ = indx;
00185     isInitialized_ = true;
00186     isPacked_ = (allvals != null);
00187   }
00188 
00189   //==============================================================================
00190   template <class Scalar, class Ordinal, class Node>
00191   bool VbrMatrix<Scalar,Ordinal,Node>::isPacked() const {
00192     return isPacked_;
00193   }
00194 
00195   //==============================================================================
00196   template <class Scalar, class Ordinal, class Node>
00197   bool VbrMatrix<Scalar,Ordinal,Node>::isEmpty() const {
00198     return isEmpty_;
00199   }
00200 
00201   //==============================================================================
00202   template <class Scalar, class Ordinal, class Node>
00203   size_t VbrMatrix<Scalar,Ordinal,Node>::getNumBlockRows() const {
00204     return numRows_;
00205   }
00206 
00207 } // namespace Kokkos
00208 
00209 
00210 #endif /* KOKKOS_VBRMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends