Tpetra Matrix/Vector Services  Version of the Day
Tpetra_MultiVector_decl.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_MULTIVECTOR_DECL_HPP
43 #define TPETRA_MULTIVECTOR_DECL_HPP
44 
45 #include <Teuchos_DataAccess.hpp>
46 #include <Teuchos_Range1D.hpp>
47 #include "Tpetra_ConfigDefs.hpp"
48 #include "Tpetra_DistObject.hpp"
49 #include "Tpetra_ViewAccepter.hpp"
50 #include <Kokkos_MultiVector.hpp>
51 #include <Teuchos_BLAS_types.hpp>
52 
53 namespace Kokkos {
54 #ifndef DOXYGEN_SHOULD_SKIP_THIS
55  // forward declaration of DefaultArithmetic
56  template<class KokkosMultiVectorType>
57  class DefaultArithmetic;
58 #endif // DOXYGEN_SHOULD_SKIP_THIS
59 } // namespace Kokkos
60 
61 namespace Tpetra {
62 
63 #ifndef DOXYGEN_SHOULD_SKIP_THIS
64  // forward declaration of Vector, needed to prevent circular inclusions
65  template<class S, class LO, class GO, class N> class Vector;
66 
67  // forward declaration of Map
68  template<class LO, class GO, class N> class Map;
69 #endif // DOXYGEN_SHOULD_SKIP_THIS
70 
319  template<class Scalar,
320  class LocalOrdinal=int,
321  class GlobalOrdinal=LocalOrdinal,
322  class Node=Kokkos::DefaultNode::DefaultNodeType>
323  class MultiVector :
324  public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
325  {
326  public:
328 
329 
331  typedef Scalar scalar_type;
333  typedef LocalOrdinal local_ordinal_type;
335  typedef GlobalOrdinal global_ordinal_type;
337  typedef Node node_type;
338 
340 
342 
350  size_t NumVectors,
351  bool zeroOut=true);
352 
355 
373  size_t LDA,
374  size_t NumVectors);
375 
390  const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
391  size_t NumVectors);
392 
394  virtual ~MultiVector();
395 
397 
399 
408  void
409  replaceGlobalValue (GlobalOrdinal globalRow,
410  size_t vectorIndex,
411  const Scalar &value);
412 
421  void
422  sumIntoGlobalValue (GlobalOrdinal globalRow,
423  size_t vectorIndex,
424  const Scalar &value);
425 
434  void
435  replaceLocalValue (LocalOrdinal myRow,
436  size_t vectorIndex,
437  const Scalar &value);
438 
447  void
448  sumIntoLocalValue (LocalOrdinal myRow,
449  size_t vectorIndex,
450  const Scalar &value);
451 
453  void putScalar (const Scalar &value);
454 
470  void randomize();
471 
537  void replaceMap (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& map);
538 
545  void reduce();
546 
562  operator= (const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& source);
563 
565 
567 
575 
578  subCopy (const Teuchos::Range1D &colRng) const;
579 
582  subCopy (const Teuchos::ArrayView<const size_t> &cols) const;
583 
586  subView (const Teuchos::Range1D &colRng) const;
587 
590  subView (const Teuchos::ArrayView<const size_t> &cols) const;
591 
594  subViewNonConst (const Teuchos::Range1D &colRng);
595 
598  subViewNonConst (const Teuchos::ArrayView<const size_t> &cols);
599 
601 
613  offsetView (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& subMap,
614  size_t offset) const;
615 
617 
629  offsetViewNonConst (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &subMap,
630  size_t offset);
631 
634  getVector (size_t j) const;
635 
638  getVectorNonConst (size_t j);
639 
641  Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
642 
644  Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
645 
652  void get1dCopy (Teuchos::ArrayView<Scalar> A, size_t LDA) const;
653 
659  void get2dCopy (Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> > ArrayOfPtrs) const;
660 
666  Teuchos::ArrayRCP<const Scalar> get1dView() const;
667 
670 
676  Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
677 
679  Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst();
680 
682  const Kokkos::MultiVector<Scalar,Node> & getLocalMV() const;
683 
685  Kokkos::MultiVector<Scalar,Node> & getLocalMVNonConst();
686 
688 
690 
691 
694 
697 
699  void reciprocal(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &A);
700 
708  void scale (const Scalar &alpha);
709 
718  void scale (Teuchos::ArrayView<const Scalar> alpha);
719 
728  void
729  scale (const Scalar& alpha,
731 
738  void
739  update (const Scalar& alpha,
741  const Scalar& beta);
742 
749  void
750  update (const Scalar& alpha,
752  const Scalar& beta,
754  const Scalar& gamma);
755 
757  void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
758 
761  void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
762 
764  void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &norms) const;
765 
769 
772  void meanValue(const Teuchos::ArrayView<Scalar> &means) const;
773 
779  void
780  multiply (Teuchos::ETransp transA,
781  Teuchos::ETransp transB,
782  const Scalar& alpha,
785  const Scalar& beta);
786 
799  void
800  elementWiseMultiply (Scalar scalarAB,
803  Scalar scalarThis);
805 
807 
809  size_t getNumVectors() const;
810 
812  size_t getLocalLength() const;
813 
815  global_size_t getGlobalLength() const;
816 
822  size_t getStride() const;
823 
827  bool isConstantStride() const;
828 
830 
832 
833 
835  virtual std::string description() const;
836 
865  virtual void
866  describe (Teuchos::FancyOStream& out,
867  const Teuchos::EVerbosityLevel verbLevel =
870 
884  virtual void
886 
887  protected:
888 
889  typedef Kokkos::MultiVector<Scalar,Node> KMV;
890  typedef Kokkos::DefaultArithmetic<KMV> MVT;
891 
893  KMV lclMV_;
894 
908 
910 
911 
912  template <class S,class LO,class GO,class N>
914  createMultiVectorFromView (const Teuchos::RCP<const Map<LO,GO,N> >&, const Teuchos::ArrayRCP<S>&, size_t, size_t);
915 
926  const Teuchos::ArrayRCP<Scalar>& view,
927  size_t LDA,
928  size_t NumVectors,
929  EPrivateHostViewConstructor /* dummy */);
930 
931  bool vectorIndexOutOfRange (size_t VectorIndex) const;
932 
938  template <class T>
939  ArrayRCP<T> getSubArrayRCP(ArrayRCP<T> arr, size_t j) const;
940 
944  size_t LDA,
946  EPrivateComputeViewConstructor /* dummy */);
947 
951  size_t LDA,
952  size_t NumVectors,
953  EPrivateComputeViewConstructor /* dummy */);
954 
963  const Kokkos::MultiVector<Scalar, Node>& localMultiVector,
964  EPrivateComputeViewConstructor /* dummy */);
965 
974  const Kokkos::MultiVector<Scalar, Node>& localMultiVector,
976  EPrivateComputeViewConstructor /* dummy */);
977 
979 
981 
986  virtual bool
987  checkSizes (const SrcDistObject& sourceObj);
988 
989  virtual void
990  copyAndPermute (const SrcDistObject& sourceObj,
991  size_t numSameIDs,
992  const ArrayView<const LocalOrdinal>& permuteToLIDs,
993  const ArrayView<const LocalOrdinal>& permuteFromLIDs);
994 
996  virtual size_t constantNumberOfPackets () const;
997 
998  virtual void
999  packAndPrepare (const SrcDistObject& sourceObj,
1000  const ArrayView<const LocalOrdinal>& exportLIDs,
1001  Array<Scalar>& exports,
1002  const ArrayView<size_t>& numExportPacketsPerLID,
1003  size_t& constantNumPackets,
1004  Distributor& distor);
1005 
1006  virtual void
1007  unpackAndCombine (const ArrayView<const LocalOrdinal>& importLIDs,
1008  const ArrayView<const Scalar>& imports,
1009  const ArrayView<size_t>& numPacketsPerLID,
1010  size_t constantNumPackets,
1011  Distributor& distor,
1012  CombineMode CM);
1013 
1014  void createViews () const;
1015  void createViewsNonConst (Kokkos::ReadWriteOption rwo);
1016  void releaseViews () const;
1017 
1020 
1023 
1025 
1027 
1034 
1036  }; // class MultiVector
1037 
1045  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1048  size_t numVectors)
1049  {
1050  using Teuchos::rcp;
1052 
1053  const bool initToZero = true;
1054  return rcp (new MV (map, numVectors, initToZero));
1055  }
1056 
1082  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1085  const Teuchos::ArrayRCP<Scalar>& view,
1086  size_t LDA,
1087  size_t numVectors)
1088  {
1089  using Teuchos::rcp;
1092 
1093  // This uses a protected MultiVector constructor, but this
1094  // nonmember function was declared a friend of MultiVector.
1095  //
1096  // The ViewAccepter expression will fail to compile for
1097  // unsupported Kokkos Node types.
1098  return rcp (new MV (map, VAN::template acceptView<Scalar> (view),
1099  LDA, numVectors, HOST_VIEW_CONSTRUCTOR));
1100  }
1101 
1102 } // namespace Tpetra
1103 
1104 
1105 #endif // TPETRA_MULTIVECTOR_DECL_HPP
Namespace Tpetra contains the class and methods constituting the Tpetra library.
ArrayRCP< Scalar > ncview_
Nonconst host view created in createViewsNonConst().
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createMultiVector(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t numVectors)
Nonmember MultiVector constructor: make a MultiVector from a given Map.
ViewAccepter provides support for compile-time detection based on Node type, of support for accepting...
One or more distributed dense vectors.
bool createViewsNonConstRaisedEfficiencyWarning_
Whether createViewsNonConst() has yet raised an efficiency warning.
GlobalOrdinal global_ordinal_type
The type of global indices.
void removeEmptyProcessesInPlace(Teuchos::RCP< DistObjectType > &input, const Teuchos::RCP< const Map< typename DistObjectType::local_ordinal_type, typename DistObjectType::global_ordinal_type, typename DistObjectType::node_type > > &newMap)
Remove processes which contain no elements in this object&#39;s Map.
Scalar scalar_type
The type of entries in the vector(s).
bool createViewsRaisedEfficiencyWarning_
Whether createViews() has yet raised an efficiency warning.
size_t global_size_t
Global size_t object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Node node_type
The Kokkos Node type.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
LocalOrdinal local_ordinal_type
The type of local indices.
bool releaseViewsRaisedEfficiencyWarning_
Whether releaseViews() has yet raised an efficiency warning.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createMultiVectorFromView(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayRCP< Scalar > &view, size_t LDA, size_t numVectors)
Nonmember MultiVector constructor with view semantics using user-allocated data.
ArrayRCP< const Scalar > cview_
Const host view created in createViews().
Abstract base class for objects that can be the source of an Import or Export operation.
static const EVerbosityLevel verbLevel_default
KMV lclMV_
The Kokkos::MultiVector containing the compute buffer of data.
Describes a parallel distribution of objects over processes.
A distributed dense vector.
Base class for distributed Tpetra objects that support data redistribution.
Array< size_t > whichVectors_
Indices of columns this multivector is viewing.