Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_MultiVector.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_MULTIVECTOR_H
00030 #define KOKKOS_MULTIVECTOR_H
00031 
00032 #include "Kokkos_ConfigDefs.hpp"
00033 #include "Kokkos_DefaultNode.hpp"
00034 
00035 #include <Teuchos_RCP.hpp>
00036 #include <Teuchos_ArrayRCP.hpp>
00037 #include <Teuchos_TestForException.hpp>
00038 #include <Teuchos_TypeNameTraits.hpp>
00039 
00040 namespace Kokkos {
00041 
00051   template<class Scalar, class Node = DefaultNode::DefaultNodeType>
00052   class MultiVector {
00053     public:
00054       typedef Scalar  ScalarType;
00055       typedef Node    NodeType;
00056 
00058 
00060 
00062       MultiVector(RCP<Node> node)
00063       : node_(node)
00064       , numRows_(0)
00065       , numCols_(0)
00066       , stride_(0) {
00067       }
00068 
00070       MultiVector(const MultiVector& source)
00071       : node_(source.node_)
00072       , contigValues_(source.contigValues_)
00073       , numRows_(source.numRows_)
00074       , numCols_(source.numCols_)
00075       , stride_(source.stride_) {
00076       }
00077 
00079       ~MultiVector() {
00080       }
00081 
00083 
00085 
00087 
00089 
00103       void initializeValues(size_t numRows, size_t numCols, 
00104                             const ArrayRCP<Scalar> &values,
00105                             size_t stride) {
00106         numRows_ = numRows;
00107         numCols_ = numCols;
00108         stride_ = stride;
00109         contigValues_ = values;
00110       };
00111 
00113 
00115 
00117 
00119       ArrayRCP<Scalar>
00120       getValuesNonConst() {
00121         return contigValues_;
00122       }
00123 
00125       ArrayRCP<const Scalar>
00126       getValues() const {
00127         return contigValues_;
00128       }
00129 
00131 
00139       ArrayRCP<Scalar>
00140       getValuesNonConst(size_t i) {
00141 #ifdef HAVE_KOKKOS_DEBUG
00142         TEST_FOR_EXCEPTION( !( (contigValues_ != null) &&  // Data to return
00143                                ( (i > 0 || i == 0) && i < numCols_)    // In range
00144                              ), std::runtime_error, 
00145                              Teuchos::typeName(*this) << "::getValuesNonConst(): index out of range or data structure not initialized.");
00146 #endif
00147         return contigValues_.persistingView(stride_*i,numRows_);
00148       };
00149 
00151 
00159       ArrayRCP<const Scalar>
00160       getValues(size_t i) const {
00161 #ifdef HAVE_KOKKOS_DEBUG
00162         TEST_FOR_EXCEPTION( !( (contigValues_ != null) &&  // Data to return
00163                                ( (i > 0 || i == 0) && i < numCols_)    // In range
00164                              ), std::runtime_error, 
00165                              Teuchos::typeName(*this) << "::getValues(): index out of range or data structure not initialized.");
00166 #endif
00167         return contigValues_.persistingView(stride_*i,numRows_);
00168       };
00169 
00171 
00173 
00175 
00176       RCP<Node> getNode() const {return node_;}
00177 
00179       size_t getNumRows() const {return(numRows_);};
00180 
00182       size_t getNumCols() const{return(numCols_);};
00183 
00185       size_t getStride() const {return(stride_);};
00186 
00188 
00189     protected:
00190       RCP<Node> node_;
00191 
00192       ArrayRCP<Scalar> contigValues_;
00193 
00194       bool dataInitialized_;
00195       size_t numRows_, numCols_, stride_;
00196   };
00197 
00198 } // namespace Kokkos
00199 
00200 #endif /* KOKKOS_MULTIVECTOR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends