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_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       typedef Scalar        scalar_type;
00067       typedef LocalOrdinal  local_ordinal_type;
00068       typedef GlobalOrdinal global_ordinal_type;
00069       typedef Node          node_type;
00070 
00072 
00073 
00075     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, size_t NumVectors, bool zeroOut=true);
00076 
00078     MultiVector(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00079 
00081 
00082     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const Teuchos::ArrayView<const Scalar> &A, size_t LDA, size_t NumVectors);
00083 
00085 
00086     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> > &ArrayOfPtrs, size_t NumVectors);
00087 
00089     virtual ~MultiVector();
00090 
00092 
00094 
00095 
00097     void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
00098 
00100     void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
00101 
00103     void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
00104 
00106     void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
00107 
00109     void putScalar(const Scalar &value);
00110 
00112     void randomize();
00113 
00115     void replaceMap(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map);
00116 
00118     void reduce();
00119 
00121 
00123     MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& operator=(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00124 
00126 
00128 
00136 
00138     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subCopy(const Teuchos::Range1D &colRng) const;
00139 
00141     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subCopy(const Teuchos::ArrayView<const size_t> &cols) const;
00142 
00144     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subView(const Teuchos::Range1D &colRng) const;
00145 
00147     Teuchos::RCP<const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subView(Teuchos::ArrayView<const size_t> cols) const;
00148 
00150     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subViewNonConst(const Teuchos::Range1D &colRng);
00151 
00153     Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > subViewNonConst(Teuchos::ArrayView<const size_t> cols);
00154 
00156     Teuchos::RCP<const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getVector(size_t j) const;
00157 
00159     Teuchos::RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getVectorNonConst(size_t j);
00160 
00163     Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
00164 
00167     Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
00168 
00170     void get1dCopy(Teuchos::ArrayView<Scalar> A, size_t LDA) const;
00171 
00173     void get2dCopy(Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> > ArrayOfPtrs) const;
00174 
00176     Teuchos::ArrayRCP<const Scalar> get1dView() const;
00177 
00179     Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView() const;
00180 
00182     Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
00183 
00185     Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst();
00186 
00188     const Kokkos::MultiVector<Scalar,Node> & getLocalMV() const;
00189 
00191     Kokkos::MultiVector<Scalar,Node> & getLocalMVNonConst();
00192 
00194 
00196 
00197 
00199     void dot(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Teuchos::ArrayView<Scalar> &dots) const;
00200 
00202     void abs(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00203 
00205     void reciprocal(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00206 
00208     void scale(const Scalar &alpha);
00209 
00211     void scale(Teuchos::ArrayView<const Scalar> alpha);
00212 
00214     void scale(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
00215 
00217     void update(const Scalar &alpha, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const Scalar &beta);
00218 
00220     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);
00221 
00223     void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00224 
00226     void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00227 
00229     void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00230 
00232     void normWeighted(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &weights, const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
00233 
00235     void meanValue(const Teuchos::ArrayView<Scalar> &means) const;
00236 
00238     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);
00239 
00241 
00246     void elementWiseMultiply(Scalar scalarAB, const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A, const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &B, Scalar scalarThis);
00248 
00250 
00251 
00253     size_t getNumVectors() const;
00254 
00256     size_t getLocalLength() const;
00257 
00259     global_size_t getGlobalLength() const;
00260 
00262     size_t getStride() const;
00263 
00265     bool isConstantStride() const;
00266 
00268 
00270 
00271 
00273     std::string description() const;
00274 
00276     void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00277 
00279 
00280     protected:
00281 
00282     typedef Kokkos::MultiVector<Scalar,Node> KMV;
00283     typedef Kokkos::DefaultArithmetic<KMV>   MVT;
00284 
00285     KMV lclMV_;
00286     Teuchos::Array<size_t> whichVectors_;
00287 
00288     template <class T>
00290     Teuchos::ArrayRCP<T> getSubArrayRCP(Teuchos::ArrayRCP<T> arr, size_t j) const;
00291 
00293     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00294                 Teuchos::ArrayRCP<Scalar> data, size_t LDA, Teuchos::ArrayView<const size_t> whichVectors);
00295 
00297     MultiVector(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00298                 Teuchos::ArrayRCP<Scalar> data, size_t LDA, size_t NumVectors);
00299 
00300     // four functions needed for DistObject derivation
00301     bool checkSizes(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj);
00302 
00303     void copyAndPermute(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj,
00304                         size_t numSameIDs,
00305                         const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
00306                         const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
00307 
00308     void packAndPrepare(const DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> &sourceObj,
00309                         const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
00310                         Teuchos::Array<Scalar> &exports,
00311                         const Teuchos::ArrayView<size_t> &numExportPacketsPerLID,
00312                         size_t& constantNumPackets,
00313                         Distributor &distor);
00314 
00315     void unpackAndCombine(const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
00316                           const Teuchos::ArrayView<const Scalar> &imports,
00317                           const Teuchos::ArrayView<size_t> &numPacketsPerLID,
00318                           size_t constantNumPackets,
00319                           Distributor &distor,
00320                           CombineMode CM);
00321 
00322   }; // class MultiVector
00323 
00324 } // namespace Tpetra
00325 
00326 
00327 #endif // TPETRA_MULTIVECTOR_DECL_HPP

Generated on Tue Jul 13 09:39:07 2010 for Tpetra Matrix/Vector Services by  doxygen 1.4.7