Tpetra_MultiVectorDecl.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 #ifndef TPETRA_MULTIVECTOR_DECL_HPP
00030 #define TPETRA_MULTIVECTOR_DECL_HPP
00031 
00032 #include <Teuchos_LabeledObject.hpp>
00033 #include <Teuchos_Array.hpp>
00034 #include <Teuchos_ArrayView.hpp>
00035 #include <Teuchos_ArrayRCP.hpp>
00036 #include <Teuchos_DataAccess.hpp>
00037 #include <Teuchos_BLAS_types.hpp>
00038 #include <Teuchos_Range1D.hpp>
00039 
00040 #include <Kokkos_MultiVector.hpp>
00041 #include <Kokkos_DefaultArithmetic.hpp>
00042 
00043 #include "Tpetra_DistObject.hpp"
00044 #include "Tpetra_Map.hpp"
00045 
00046 // TODO: add principal use case instructions for memory management interfaces (view/copy extraction)
00047 // TODO: expand user-visible documentation 
00048 
00049 namespace Tpetra {
00050 
00051 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00052   // forward declaration of Vector, needed to prevent circular inclusions
00053   template<class S, class LO, class GO, class N> class Vector;
00054 #endif
00055 
00057 
00062   template <class Scalar, class LocalOrdinal=int, class GlobalOrdinal=LocalOrdinal, class Node=Kokkos::DefaultNode::DefaultNodeType>
00063   class MultiVector : public DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
00064 
00065     public:
00066 
00068 
00069 
00071     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, size_t NumVectors, bool zeroOut=true);
00072 
00074     MultiVector(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00075 
00077 
00078     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const Teuchos::ArrayView<const Scalar> &A, size_t LDA, size_t NumVectors);
00079 
00081 
00082     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> > &ArrayOfPtrs, size_t NumVectors);
00083 
00085     virtual ~MultiVector();
00086 
00088 
00090 
00091 
00093     void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
00094 
00096     void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
00097 
00099     void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
00100 
00102     void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
00103 
00105     void putScalar(const Scalar &value);
00106 
00108     void randomize();
00109 
00111     void replaceMap(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map);
00112 
00114     void reduce();
00115 
00117 
00119     MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& operator=(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00120 
00122 
00124 
00132 
00134     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subCopy(const Teuchos::Range1D &colRng) const;
00135 
00137     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subCopy(const Teuchos::ArrayView<const size_t> &cols) const;
00138 
00140     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subView(const Teuchos::Range1D &colRng) const;
00141 
00143     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subView(Teuchos::ArrayView<const size_t> cols) const;
00144 
00146     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subViewNonConst(const Teuchos::Range1D &colRng);
00147 
00149     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subViewNonConst(Teuchos::ArrayView<const size_t> cols);
00150 
00152     Teuchos::RCP<const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getVector(size_t j) const;
00153 
00155     Teuchos::RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getVectorNonConst(size_t j);
00156 
00159     Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
00160 
00163     Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
00164 
00166     void get1dCopy(Teuchos::ArrayView<Scalar> A, size_t LDA) const;
00167 
00169     void get2dCopy(Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> > ArrayOfPtrs) const;
00170 
00172     Teuchos::ArrayRCP<const Scalar> get1dView() const;
00173 
00175     Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView() const;
00176 
00178     Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
00179 
00181     Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst();
00182 
00184     const Kokkos::MultiVector<Scalar,Node> & getLocalMV() const;
00185 
00187     Kokkos::MultiVector<Scalar,Node> & getLocalMVNonConst();
00188 
00190 
00192 
00193 
00195     void dot(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Teuchos::ArrayView<Scalar> &dots) const;
00196 
00198     void abs(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00199 
00201     void reciprocal(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00202 
00204     void scale(const Scalar &alpha);
00205 
00207     void scale(Teuchos::ArrayView<const Scalar> alpha);
00208 
00210     void scale(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00211 
00213     void update(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Scalar &beta);
00214 
00216     void update(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Scalar &beta, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &B, const Scalar &gamma);
00217 
00219     void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00220 
00222     void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00223 
00225     void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00226 
00228     void normWeighted(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &weights, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00229 
00231     void meanValue(const Teuchos::ArrayView<Scalar> &means) const;
00232 
00234     void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &B, const Scalar &beta);
00235 
00237 
00239 
00240 
00242     size_t getNumVectors() const;
00243 
00245     size_t getLocalLength() const;
00246 
00248     global_size_t getGlobalLength() const;
00249 
00251     size_t getStride() const;
00252 
00254     bool isConstantStride() const;
00255 
00257 
00259 
00260 
00262     std::string description() const;
00263 
00265     void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00266 
00268 
00269     protected:
00270 
00271     typedef Kokkos::MultiVector<Scalar,Node> KMV;
00272     typedef Kokkos::DefaultArithmetic<KMV>   MVT;
00273 
00274     KMV lclMV_;
00275     Teuchos::Array<size_t> whichVectors_;
00276 
00277     template <class T>
00279     Teuchos::ArrayRCP<T> getSubArrayRCP(Teuchos::ArrayRCP<T> arr, size_t j) const;
00280 
00282     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00283                 Teuchos::ArrayRCP<Scalar> data, size_t LDA, Teuchos::ArrayView<const size_t> whichVectors);
00284 
00286     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00287                 Teuchos::ArrayRCP<Scalar> data, size_t LDA, size_t NumVectors);
00288 
00289     // four functions needed for DistObject derivation
00290     bool checkSizes(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj, size_t &packetSize);
00291 
00292     void copyAndPermute(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj,
00293                         size_t numSameIDs,
00294                         const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
00295                         const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
00296 
00297     void packAndPrepare(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj,
00298                         const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
00299                         const Teuchos::ArrayView<Scalar> &exports,
00300                         Distributor &distor);
00301 
00302     void unpackAndCombine(const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
00303                           const Teuchos::ArrayView<const Scalar> &imports,
00304                           Distributor &distor,
00305                           CombineMode CM);
00306 
00307   }; // class MultiVector
00308 
00309 } // namespace Tpetra
00310 
00311 
00312 #endif // TPETRA_MULTIVECTOR_DECL_HPP

Generated on Wed May 12 21:40:14 2010 for Tpetra Matrix/Vector Services by  doxygen 1.4.7