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