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 (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_MULTIVECTOR_H
00043 #define KOKKOS_MULTIVECTOR_H
00044 
00045 #include "Kokkos_ConfigDefs.hpp"
00046 #include "Kokkos_DefaultNode.hpp"
00047 
00048 #include <Teuchos_RCP.hpp>
00049 #include <Teuchos_ArrayRCP.hpp>
00050 #include <Teuchos_Assert.hpp>
00051 #include <Teuchos_TypeNameTraits.hpp>
00052 
00053 namespace Kokkos {
00054 
00064   template<class Scalar, class Node = DefaultNode::DefaultNodeType>
00065   class MultiVector {
00066     public:
00067       typedef Scalar  ScalarType;
00068       typedef Node    NodeType;
00069 
00071 
00073 
00075       MultiVector(RCP<Node> node)
00076       : node_(node)
00077       , numRows_(0)
00078       , numCols_(0)
00079       , stride_(0) {
00080       }
00081 
00083       MultiVector(const MultiVector& source)
00084       : node_(source.node_)
00085       , contigValues_(source.contigValues_)
00086       , numRows_(source.numRows_)
00087       , numCols_(source.numCols_)
00088       , stride_(source.stride_) {
00089       }
00090 
00092       ~MultiVector() {
00093       }
00094 
00096 
00098 
00100 
00102 
00116       void initializeValues(size_t numRows, size_t numCols, 
00117                             const ArrayRCP<Scalar> &values,
00118                             size_t stride) {
00119         numRows_ = numRows;
00120         numCols_ = numCols;
00121         stride_ = stride;
00122         contigValues_ = values;
00123       };
00124 
00126 
00128 
00130 
00132       ArrayRCP<Scalar>
00133       getValuesNonConst() {
00134         return contigValues_;
00135       }
00136 
00138       ArrayRCP<const Scalar>
00139       getValues() const {
00140         return contigValues_;
00141       }
00142 
00144 
00152       ArrayRCP<Scalar>
00153       getValuesNonConst(size_t i) {
00154 #ifdef HAVE_KOKKOS_DEBUG
00155         TEUCHOS_TEST_FOR_EXCEPTION( !( (contigValues_ != null) &&  // Data to return
00156                                ( (i > 0 || i == 0) && i < numCols_)    // In range
00157                              ), std::runtime_error, 
00158                              Teuchos::typeName(*this) << "::getValuesNonConst(): index out of range or data structure not initialized.");
00159 #endif
00160         return contigValues_.persistingView(stride_*i,numRows_);
00161       };
00162 
00164 
00172       ArrayRCP<const Scalar>
00173       getValues(size_t i) const {
00174 #ifdef HAVE_KOKKOS_DEBUG
00175         TEUCHOS_TEST_FOR_EXCEPTION( !( (contigValues_ != null) &&  // Data to return
00176                                ( (i > 0 || i == 0) && i < numCols_)    // In range
00177                              ), std::runtime_error, 
00178                              Teuchos::typeName(*this) << "::getValues(): index out of range or data structure not initialized.");
00179 #endif
00180         return contigValues_.persistingView(stride_*i,numRows_);
00181       };
00182 
00184 
00186 
00188 
00190       RCP<Node> getNode() const {return node_;}
00191 
00193       size_t getNumRows() const {return(numRows_);};
00194 
00196       size_t getNumCols() const{return(numCols_);};
00197 
00199       size_t getStride() const {return(stride_);};
00200 
00202 
00203     protected:
00204       RCP<Node> node_;
00205 
00206       ArrayRCP<Scalar> contigValues_;
00207 
00208       bool dataInitialized_;
00209       size_t numRows_, numCols_, stride_;
00210   };
00211 
00212 } // namespace Kokkos
00213 
00214 #endif /* KOKKOS_MULTIVECTOR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends