Tpetra_MultiVector_decl.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_ConfigDefs.hpp"
00044 #include "Tpetra_DistObject.hpp"
00045 #include "Tpetra_Map.hpp"
00046 
00047 // TODO: add principal use case instructions for memory management interfaces (view/copy extraction)
00048 // TODO: expand user-visible documentation 
00049 
00050 namespace Tpetra {
00051 
00052 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00053   // forward declaration of Vector, needed to prevent circular inclusions
00054   template<class S, class LO, class GO, class N> class Vector;
00055 #endif
00056 
00058 
00063   template <class Scalar, class LocalOrdinal=int, class GlobalOrdinal=LocalOrdinal, class Node=Kokkos::DefaultNode::DefaultNodeType>
00064   class MultiVector : public DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
00065 
00066     public:
00067       typedef Scalar        scalar_type;
00068       typedef LocalOrdinal  local_ordinal_type;
00069       typedef GlobalOrdinal global_ordinal_type;
00070       typedef Node          node_type;
00071 
00073 
00074 
00076     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, size_t NumVectors, bool zeroOut=true);
00077 
00079     MultiVector(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00080 
00082 
00083     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const Teuchos::ArrayView<const Scalar> &A, size_t LDA, size_t NumVectors);
00084 
00086 
00087     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> > &ArrayOfPtrs, size_t NumVectors);
00088 
00090     virtual ~MultiVector();
00091 
00093 
00095 
00096 
00098     void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
00099 
00101     void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
00102 
00104     void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
00105 
00107     void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
00108 
00110     void putScalar(const Scalar &value);
00111 
00113     void randomize();
00114 
00116     void replaceMap(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map);
00117 
00119     void reduce();
00120 
00122 
00124     MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& operator=(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00125 
00127 
00129 
00137 
00139     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subCopy(const Teuchos::Range1D &colRng) const;
00140 
00142     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subCopy(const Teuchos::ArrayView<const size_t> &cols) const;
00143 
00145     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subView(const Teuchos::Range1D &colRng) const;
00146 
00148     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subView(Teuchos::ArrayView<const size_t> cols) const;
00149 
00151     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subViewNonConst(const Teuchos::Range1D &colRng);
00152 
00154     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subViewNonConst(Teuchos::ArrayView<const size_t> cols);
00155 
00157 
00165     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > offsetView(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &subMap, size_t offset) const;
00166 
00168 
00176     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > offsetViewNonConst(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &subMap, size_t offset);
00177 
00179     Teuchos::RCP<const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getVector(size_t j) const;
00180 
00182     Teuchos::RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getVectorNonConst(size_t j);
00183 
00186     Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
00187 
00190     Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
00191 
00193     void get1dCopy(Teuchos::ArrayView<Scalar> A, size_t LDA) const;
00194 
00196     void get2dCopy(Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> > ArrayOfPtrs) const;
00197 
00199     Teuchos::ArrayRCP<const Scalar> get1dView() const;
00200 
00202     Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView() const;
00203 
00205     Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
00206 
00208     Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst();
00209 
00211     const Kokkos::MultiVector<Scalar,Node> & getLocalMV() const;
00212 
00214     Kokkos::MultiVector<Scalar,Node> & getLocalMVNonConst();
00215 
00217 
00219 
00220 
00222     void dot(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Teuchos::ArrayView<Scalar> &dots) const;
00223 
00225     void abs(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00226 
00228     void reciprocal(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00229 
00231     void scale(const Scalar &alpha);
00232 
00234     void scale(Teuchos::ArrayView<const Scalar> alpha);
00235 
00237     void scale(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00238 
00240     void update(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Scalar &beta);
00241 
00243     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);
00244 
00246     void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00247 
00249     void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00250 
00252     void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00253 
00255     void normWeighted(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &weights, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00256 
00258     void meanValue(const Teuchos::ArrayView<Scalar> &means) const;
00259 
00261     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);
00262 
00264 
00269     void elementWiseMultiply(Scalar scalarAB, const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &B, Scalar scalarThis);
00271 
00273 
00274 
00276     size_t getNumVectors() const;
00277 
00279     size_t getLocalLength() const;
00280 
00282     global_size_t getGlobalLength() const;
00283 
00285     size_t getStride() const;
00286 
00288     bool isConstantStride() const;
00289 
00291 
00293 
00294 
00296     std::string description() const;
00297 
00299     void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00300 
00302 
00303     protected:
00304 
00305     typedef Kokkos::MultiVector<Scalar,Node> KMV;
00306     typedef Kokkos::DefaultArithmetic<KMV>   MVT;
00307 
00308     KMV lclMV_;
00309     Teuchos::Array<size_t> whichVectors_;
00310 
00311     template <class T>
00313     Teuchos::ArrayRCP<T> getSubArrayRCP(Teuchos::ArrayRCP<T> arr, size_t j) const;
00314 
00316     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00317                 Teuchos::ArrayRCP<Scalar> data, size_t LDA, Teuchos::ArrayView<const size_t> whichVectors);
00318 
00320     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00321                 Teuchos::ArrayRCP<Scalar> data, size_t LDA, size_t NumVectors);
00322 
00323     // four functions needed for DistObject derivation
00324     bool checkSizes(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj);
00325 
00326     void copyAndPermute(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj,
00327                         size_t numSameIDs,
00328                         const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
00329                         const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
00330 
00331     void packAndPrepare(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj,
00332                         const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
00333                         Teuchos::Array<Scalar> &exports,
00334                         const Teuchos::ArrayView<size_t> &numExportPacketsPerLID,
00335                         size_t& constantNumPackets,
00336                         Distributor &distor);
00337 
00338     void unpackAndCombine(const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
00339                           const Teuchos::ArrayView<const Scalar> &imports,
00340                           const Teuchos::ArrayView<size_t> &numPacketsPerLID,
00341                           size_t constantNumPackets,
00342                           Distributor &distor,
00343                           CombineMode CM);
00344 
00345   mutable Teuchos::ArrayRCP<Scalar> ncview_;
00346   mutable Teuchos::ArrayRCP<const Scalar> cview_;
00347 
00348   void createViews() const;
00349   void createViewsNonConst(Kokkos::ReadWriteOption rwo);
00350   void releaseViews() const;
00351 
00352   }; // class MultiVector
00353 
00357   template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00358   Teuchos::RCP< MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00359   createMultiVector(const Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, size_t numVectors);
00360 
00361 
00362 } // namespace Tpetra
00363 
00364 
00365 #endif // TPETRA_MULTIVECTOR_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:21:41 2011 for Tpetra Matrix/Vector Services by  doxygen 1.6.3