Tpetra parallel linear algebra  Version of the Day
Tpetra_Experimental_BlockMultiVector_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_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
43 #define TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
44 
45 #include <Tpetra_MultiVector.hpp>
47 
48 namespace Tpetra {
49 namespace Experimental {
50 
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 // Forward declaration of BlockCrsMatrix, needed for debugging.
53 template<class S, class LO, class GO, class N> class BlockCrsMatrix;
54 #endif // DOXYGEN_SHOULD_SKIP_THIS
55 
144 template<class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
146  class GO = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
149  public Tpetra::DistObject<Scalar, LO, GO, Node>
150 {
151 private:
153  typedef Teuchos::ScalarTraits<Scalar> STS;
154 
155 protected:
156  typedef Scalar packet_type;
157 
158 public:
160 
161 
166 
168  typedef Scalar scalar_type;
177  typedef LO local_ordinal_type;
181  typedef typename Node::device_type device_type;
182 
184  typedef Node node_type;
185 
201  typedef Kokkos::View<impl_scalar_type*,
202  Kokkos::LayoutRight,
203  device_type,
204  Kokkos::MemoryTraits<Kokkos::Unmanaged> >
206 
212  typedef Kokkos::View<const impl_scalar_type*,
213  Kokkos::LayoutRight,
214  device_type,
215  Kokkos::MemoryTraits<Kokkos::Unmanaged> >
217 
219 
221 
252  BlockMultiVector (const map_type& meshMap,
253  const LO blockSize,
254  const LO numVecs);
255 
260  BlockMultiVector (const map_type& meshMap,
261  const map_type& pointMap,
262  const LO blockSize,
263  const LO numVecs);
264 
277  BlockMultiVector (const mv_type& X_mv,
278  const map_type& meshMap,
279  const LO blockSize);
280 
286  const map_type& newMeshMap,
287  const map_type& newPointMap,
288  const size_t offset = 0);
289 
295  const map_type& newMeshMap,
296  const size_t offset = 0);
297 
302  BlockMultiVector ();
303 
305 
307 
314  static map_type
315  makePointMap (const map_type& meshMap, const LO blockSize);
316 
322  return pointMap_;
323  }
324 
326  LO getBlockSize () const {
327  return blockSize_;
328  }
329 
331  LO getNumVectors () const {
332  return static_cast<LO> (mv_.getNumVectors ());
333  }
334 
340  mv_type getMultiVectorView () const;
341 
343 
345 
347  void putScalar (const Scalar& val);
348 
350  void scale (const Scalar& val);
351 
358  void
359  update (const Scalar& alpha,
361  const Scalar& beta);
362 
384  void
385  blockWiseMultiply (const Scalar& alpha,
386  const Kokkos::View<const impl_scalar_type***,
387  device_type, Kokkos::MemoryUnmanaged>& D,
389 
420  void
421  blockJacobiUpdate (const Scalar& alpha,
422  const Kokkos::View<const impl_scalar_type***,
423  device_type, Kokkos::MemoryUnmanaged>& D,
426  const Scalar& beta);
427 
429 
431 
450  template<class TargetMemorySpace>
451  void sync () {
452  mv_.template sync<typename TargetMemorySpace::memory_space> ();
453  }
454 
456  template<class TargetMemorySpace>
457  bool need_sync () const {
458  return mv_.template need_sync<typename TargetMemorySpace::memory_space> ();
459  }
460 
466  template<class TargetMemorySpace>
467  void modify () {
468  mv_.template modify<typename TargetMemorySpace::memory_space> ();
469  }
470 
472 
474 
492  bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
493 
504  bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
505 
516  bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
517 
528  bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
529 
540  bool getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals) const;
541 
552  bool getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals) const;
553 
565  typename little_vec_type::HostMirror
566  getLocalBlock (const LO localRowIndex, const LO colIndex) const;
568 
569 protected:
575 
576 
577  virtual bool checkSizes (const Tpetra::SrcDistObject& source);
578 
579  virtual void
580  copyAndPermute (const Tpetra::SrcDistObject& source,
581  size_t numSameIDs,
582  const Teuchos::ArrayView<const LO>& permuteToLIDs,
583  const Teuchos::ArrayView<const LO>& permuteFromLIDs);
584 
585  virtual void
586  packAndPrepare (const Tpetra::SrcDistObject& source,
587  const Teuchos::ArrayView<const LO>& exportLIDs,
588  Teuchos::Array<impl_scalar_type>& exports,
589  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
590  size_t& constantNumPackets,
591  Tpetra::Distributor& distor);
592 
593  virtual void
594  unpackAndCombine (const Teuchos::ArrayView<const LO> &importLIDs,
595  const Teuchos::ArrayView<const impl_scalar_type> &imports,
596  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
597  size_t constantNumPackets,
598  Tpetra::Distributor& distor,
601 
602 protected:
605  return mvData_;
606  }
607 
609  size_t getStrideX () const {
610  return static_cast<size_t> (1);
611  }
612 
614  size_t getStrideY () const {
615  return mv_.getStride ();
616  }
617 
620  bool isValidLocalMeshIndex (const LO meshLocalIndex) const {
621  return meshLocalIndex != Teuchos::OrdinalTraits<LO>::invalid () &&
622  meshMap_.isNodeLocalElement (meshLocalIndex);
623  }
624 
625 private:
626  // mfh 20 May 2014: I'm only using this for debugging.
627  template<class Scalar2, class LO2, class GO2, class Node2>
628  friend class BlockCrsMatrix;
629 
635  map_type meshMap_;
636 
638  map_type pointMap_;
639 
640 protected:
643 
644 private:
653  impl_scalar_type* mvData_;
654 
656  LO blockSize_;
657 
659  void
660  replaceLocalValuesImpl (const LO localRowIndex,
661  const LO colIndex,
662  const Scalar vals[]) const;
664  void
665  sumIntoLocalValuesImpl (const LO localRowIndex,
666  const LO colIndex,
667  const Scalar vals[]) const;
668 
669  static Teuchos::RCP<const mv_type>
670  getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
671 
672  static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
673  getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
674 };
675 
676 } // namespace Experimental
677 } // namespace Tpetra
678 
679 #endif // TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
void sync()
Update data to the given target memory space, only if data in the "other" space have been marked as m...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
size_t getStride() const
Stride between columns in the multivector.
mv_type mv_
The Tpetra::MultiVector used to represent the data.
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using a global index.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
bool getGlobalRowView(const GO globalRowIndex, const LO colIndex, Scalar *&vals) const
Get a writeable view of the entries at the given mesh point, using a global index.
size_t getStrideY() const
Stride between consecutive local entries in the same row.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
Tpetra::Map< LO, GO, Node > map_type
The specialization of Tpetra::Map that this class uses.
bool need_sync() const
Whether this object needs synchronization to the given memory space.
MultiVector for multiple degrees of freedom per mesh point.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
static map_type makePointMap(const map_type &meshMap, const LO blockSize)
Create and return the point Map corresponding to the given mesh Map and block size.
Kokkos::View< impl_scalar_type *, Kokkos::LayoutRight, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > little_vec_type
"Block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector...
virtual void unpackAndCombine(const Teuchos::ArrayView< const LO > &importLIDs, const Teuchos::ArrayView< const impl_scalar_type > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Tpetra::Distributor &distor, Tpetra::CombineMode CM)
Perform any unpacking and combining after communication (old version that uses Teuchos memory managem...
int local_ordinal_type
Default value of LocalOrdinal template parameter.
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
bool sumIntoLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[]) const
Sum into all values at the given mesh point, using a local index.
bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const
Sum into all values at the given mesh point, using a global index.
bool replaceLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using local row and column indices.
Linear algebra kernels for small dense matrices and vectors.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
void blockJacobiUpdate(const Scalar &alpha, const Kokkos::View< const impl_scalar_type ***, device_type, Kokkos::MemoryUnmanaged > &D, const BlockMultiVector< Scalar, LO, GO, Node > &X, BlockMultiVector< Scalar, LO, GO, Node > &Z, const Scalar &beta)
Block Jacobi update .
void blockWiseMultiply(const Scalar &alpha, const Kokkos::View< const impl_scalar_type ***, device_type, Kokkos::MemoryUnmanaged > &D, const BlockMultiVector< Scalar, LO, GO, Node > &X)
*this := alpha * D * X, where D is a block diagonal matrix.
Abstract base class for objects that can be the source of an Import or Export operation.
double scalar_type
Default value of Scalar template parameter.
mv_type getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector&#39;s data.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
void modify()
Mark data as modified on the given memory space.
virtual bool checkSizes(const Tpetra::SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
Kokkos::View< const impl_scalar_type *, Kokkos::LayoutRight, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > const_little_vec_type
"Const block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector...
size_t getNumVectors() const
Number of columns in the multivector.
bool getLocalRowView(const LO localRowIndex, const LO colIndex, Scalar *&vals) const
Get a writeable view of the entries at the given mesh point, using a local index. ...
little_vec_type::HostMirror getLocalBlock(const LO localRowIndex, const LO colIndex) const
Get a host view of the degrees of freedom at the given mesh point.
Sparse matrix whose entries are small dense square blocks, all of the same dimensions.
virtual void copyAndPermute(const Tpetra::SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LO > &permuteToLIDs, const Teuchos::ArrayView< const LO > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
size_t getStrideX() const
Stride between consecutive local entries in the same column.
impl_scalar_type * getRawPtr() const
Raw pointer to the MultiVector&#39;s data.
map_type getPointMap() const
Get this BlockMultiVector&#39;s (previously computed) point Map.
virtual void packAndPrepare(const Tpetra::SrcDistObject &source, const Teuchos::ArrayView< const LO > &exportLIDs, Teuchos::Array< impl_scalar_type > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Tpetra::Distributor &distor)
Perform any packing or preparation required for communication.
Base class for distributed Tpetra objects that support data redistribution.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on the calling process.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.