Tpetra Matrix/Vector Services Version of the Day
Tpetra_Vector_decl.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //          Tpetra: Templated Linear Algebra Services Package
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 TPETRA_VECTOR_DECL_HPP
00043 #define TPETRA_VECTOR_DECL_HPP
00044 
00045 #include "Tpetra_ConfigDefs.hpp"
00046 #include "Tpetra_MultiVector_decl.hpp"
00047 
00048 namespace Tpetra {
00049 
00057 template<class Scalar=double,
00058          class LocalOrdinal=int,
00059          class GlobalOrdinal=LocalOrdinal,
00060          class Node=KokkosClassic::DefaultNode::DefaultNodeType>
00061 class Vector : public MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
00062   // need this so that MultiVector::operator() can call Vector's private view constructor
00063   friend class MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>;
00064 
00065 
00066 public:
00067   typedef typename MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::dot_type dot_type;
00068 
00070 
00071 
00073   explicit Vector(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, bool zeroOut=true);
00074 
00076   Vector(const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &source);
00077 
00079   Vector(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, const ArrayView<const Scalar> &A);
00080 
00082   virtual ~Vector();
00083 
00085 
00086 
00087 
00089   template <class Node2>
00090   RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >
00091   clone(const RCP<Node2> &node2);
00092 
00093 
00095 
00097   void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
00098 
00100 
00102   void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
00103 
00105 
00107   void replaceLocalValue(LocalOrdinal myRow, const Scalar &value);
00108 
00110 
00112   void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value);
00113 
00115 
00117 
00118 
00119   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::get1dCopy; // overloading, not hiding
00121   void get1dCopy(ArrayView<Scalar> A) const;
00122 
00123   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getDataNonConst; // overloading, not hiding
00125   Teuchos::ArrayRCP<Scalar> getDataNonConst()     { return getDataNonConst(0); }
00126 
00127   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getData; // overloading, not hiding
00129   Teuchos::ArrayRCP<const Scalar> getData() const { return getData(0); }
00130 
00132 
00134 
00135 
00136   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::dot; // overloading, not hiding
00138   Scalar dot(const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &a) const;
00139 
00140   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm1; // overloading, not hiding
00142   typename Teuchos::ScalarTraits<Scalar>::magnitudeType norm1() const;
00143 
00144   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm2; // overloading, not hiding
00146   typename Teuchos::ScalarTraits<Scalar>::magnitudeType norm2() const;
00147 
00148   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normInf; // overloading, not hiding
00150   typename Teuchos::ScalarTraits<Scalar>::magnitudeType normInf() const;
00151 
00152   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normWeighted; // overloading, not hiding
00154   typename Teuchos::ScalarTraits<Scalar>::magnitudeType normWeighted(const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &weights) const;
00155 
00156   using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::meanValue; // overloading, not hiding
00158   Scalar meanValue() const;
00159 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00244   Teuchos::RCP<const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00245   offsetView (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& subMap,
00246               size_t offset) const;
00247 
00265   Teuchos::RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00266   offsetViewNonConst (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &subMap,
00267                       size_t offset);
00268 
00270 
00271 
00272 
00274   virtual std::string description() const;
00275 
00277   virtual void
00278   describe (Teuchos::FancyOStream& out,
00279             const Teuchos::EVerbosityLevel verbLevel =
00280             Teuchos::Describable::verbLevel_default) const;
00282 
00283 protected:
00284 
00285   template <class S,class LO,class GO,class N>
00286   friend RCP< Vector<S,LO,GO,N> >
00287   createVectorFromView(const RCP<const Map<LO,GO,N> > &,const ArrayRCP<S> &);
00288 
00289   // view constructor, sitting on user allocated data, only for CPU nodes
00290   // and his non-member constructor friend
00291   Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00292           const ArrayRCP<Scalar> &view,
00293           EPrivateHostViewConstructor /* dummy tag */);
00294 
00296   Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00297           const ArrayRCP<Scalar> & data);
00298 
00300   Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00301           const ArrayRCP<Scalar> & data,
00302           EPrivateComputeViewConstructor /* dummy tag */);
00303 
00304   typedef KokkosClassic::MultiVector<Scalar,Node> KMV;
00305   typedef KokkosClassic::DefaultArithmetic<KMV>   MVT;
00306 }; // class Vector
00307 
00311 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00312 RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00313 createVector (const RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > &map)
00314 {
00315   const bool DO_INIT_TO_ZERO = true;
00316   return rcp (new Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map, DO_INIT_TO_ZERO));
00317 }
00318 
00320 
00323 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00324 RCP<Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00325 createVectorFromView (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
00326                       const ArrayRCP<Scalar> &view)
00327 {
00328   return rcp(
00329     // this is a protected constructor, but we are friends
00330     new Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00331       map,
00332       // this will fail to compile for unsupported node types
00333       Tpetra::details::ViewAccepter<Node>::template acceptView<Scalar>(view),
00334       HOST_VIEW_CONSTRUCTOR)
00335   );
00336 }
00337 
00338 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00339 template <class Node2>
00340 RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >
00341 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::clone(const RCP<Node2> &node2){
00342         typedef Map<LocalOrdinal,GlobalOrdinal,Node2> Map2;
00343         typedef Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node2> V2;
00344         Teuchos::ArrayRCP<const Scalar> V_view = this->getData();
00345         Teuchos::RCP<const Map2> clonedMap = this->getMap()->template clone<Node2> (node2);
00346         Teuchos::RCP<V2> clonedV = Teuchos::rcp(new V2(clonedMap));
00347         Teuchos::ArrayRCP<Scalar> clonedV_view = clonedV->getDataNonConst();
00348         clonedV_view.deepCopy(V_view());
00349         clonedV_view = Teuchos::null;
00350         return clonedV;
00351   }
00352 
00353 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00354 Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node >
00355   createCopy( const Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node >& src);
00356 } // namespace Tpetra
00357 
00358 // Include KokkosRefactor partial specialisation if enabled
00359 #if defined(TPETRA_HAVE_KOKKOS_REFACTOR)
00360 #include "Tpetra_KokkosRefactor_Vector_decl.hpp"
00361 #endif
00362 
00363 #endif // TPETRA_VECTOR_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines