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 
47 #include "Tpetra_MultiVector.hpp"
49 #include "Teuchos_OrdinalTraits.hpp"
50 
51 namespace Tpetra {
52 namespace Experimental {
53 namespace Classes {
54 
143 template<class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
145  class GO = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
148  public Tpetra::DistObject<Scalar, LO, GO, Node>
149 {
150 private:
152  typedef Teuchos::ScalarTraits<Scalar> STS;
153 
154 protected:
155  typedef Scalar packet_type;
156 
157 public:
159 
160 
165 
167  typedef Scalar scalar_type;
175  typedef LO local_ordinal_type;
179  typedef typename Node::device_type device_type;
180 
182  typedef Node node_type;
183 
199  typedef Kokkos::View<impl_scalar_type*,
200  Kokkos::LayoutRight,
201  device_type,
202  Kokkos::MemoryTraits<Kokkos::Unmanaged> >
204 
210  typedef Kokkos::View<const impl_scalar_type*,
211  Kokkos::LayoutRight,
212  device_type,
213  Kokkos::MemoryTraits<Kokkos::Unmanaged> >
215 
217 
219 
250  BlockMultiVector (const map_type& meshMap,
251  const LO blockSize,
252  const LO numVecs);
253 
258  BlockMultiVector (const map_type& meshMap,
259  const map_type& pointMap,
260  const LO blockSize,
261  const LO numVecs);
262 
275  BlockMultiVector (const mv_type& X_mv,
276  const map_type& meshMap,
277  const LO blockSize);
278 
284  const map_type& newMeshMap,
285  const map_type& newPointMap,
286  const size_t offset = 0);
287 
293  const map_type& newMeshMap,
294  const size_t offset = 0);
295 
300  BlockMultiVector ();
301 
303 
305 
312  static map_type
313  makePointMap (const map_type& meshMap, const LO blockSize);
314 
319  map_type getPointMap () const {
320  return pointMap_;
321  }
322 
324  LO getBlockSize () const {
325  return blockSize_;
326  }
327 
329  LO getNumVectors () const {
330  return static_cast<LO> (mv_.getNumVectors ());
331  }
332 
338  mv_type getMultiVectorView () const;
339 
341 
343 
345  void putScalar (const Scalar& val);
346 
348  void scale (const Scalar& val);
349 
356  void
357  update (const Scalar& alpha,
359  const Scalar& beta);
360 
382  void
383  blockWiseMultiply (const Scalar& alpha,
384  const Kokkos::View<const impl_scalar_type***,
385  device_type, Kokkos::MemoryUnmanaged>& D,
387 
418  void
419  blockJacobiUpdate (const Scalar& alpha,
420  const Kokkos::View<const impl_scalar_type***,
421  device_type, Kokkos::MemoryUnmanaged>& D,
424  const Scalar& beta);
425 
427 
429 
448  template<class TargetMemorySpace>
449  void sync () {
450  mv_.template sync<typename TargetMemorySpace::memory_space> ();
451  }
452 
454  template<class TargetMemorySpace>
455  bool need_sync () const {
456  return mv_.template need_sync<typename TargetMemorySpace::memory_space> ();
457  }
458 
464  template<class TargetMemorySpace>
465  void modify () {
466  mv_.template modify<typename TargetMemorySpace::memory_space> ();
467  }
468 
470 
472 
490  bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
491 
502  bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
503 
514  bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
515 
526  bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
527 
538  bool getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals) const;
539 
550  bool getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals) const;
551 
563  typename little_vec_type::HostMirror
564  getLocalBlock (const LO localRowIndex, const LO colIndex) const;
566 
567 protected:
573 
574 
575  virtual bool checkSizes (const Tpetra::SrcDistObject& source);
576 
577  virtual void
578  copyAndPermute (const Tpetra::SrcDistObject& source,
579  size_t numSameIDs,
580  const Teuchos::ArrayView<const LO>& permuteToLIDs,
581  const Teuchos::ArrayView<const LO>& permuteFromLIDs);
582 
583  virtual void
584  packAndPrepare (const Tpetra::SrcDistObject& source,
585  const Teuchos::ArrayView<const LO>& exportLIDs,
586  Teuchos::Array<impl_scalar_type>& exports,
587  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
588  size_t& constantNumPackets,
589  Tpetra::Distributor& distor);
590 
591  virtual void
592  unpackAndCombine (const Teuchos::ArrayView<const LO> &importLIDs,
593  const Teuchos::ArrayView<const impl_scalar_type> &imports,
594  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
595  size_t constantNumPackets,
596  Tpetra::Distributor& distor,
599 
600 protected:
602  impl_scalar_type* getRawPtr () const {
603  return mvData_;
604  }
605 
607  size_t getStrideX () const {
608  return static_cast<size_t> (1);
609  }
610 
612  size_t getStrideY () const {
613  return mv_.getStride ();
614  }
615 
618  bool isValidLocalMeshIndex (const LO meshLocalIndex) const {
619  return meshLocalIndex != Teuchos::OrdinalTraits<LO>::invalid () &&
620  meshMap_.isNodeLocalElement (meshLocalIndex);
621  }
622 
623 private:
629  map_type meshMap_;
630 
632  map_type pointMap_;
633 
634 protected:
636  mv_type mv_;
637 
638 private:
647  impl_scalar_type* mvData_;
648 
650  LO blockSize_;
651 
653  void
654  replaceLocalValuesImpl (const LO localRowIndex,
655  const LO colIndex,
656  const Scalar vals[]) const;
658  void
659  sumIntoLocalValuesImpl (const LO localRowIndex,
660  const LO colIndex,
661  const Scalar vals[]) const;
662 
663  static Teuchos::RCP<const mv_type>
664  getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
665 
666  static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
667  getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
668 };
669 
670 } // namespace Classes
671 } // namespace Experimental
672 } // namespace Tpetra
673 
674 #endif // TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
Base class for distributed Tpetra objects that support data redistribution.
mv_type getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector&#39;s data.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
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...
bool need_sync() const
Whether this object needs synchronization to the given memory space.
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.
Forward declaration of Tpetra::Experimental::BlockCrsMatrix.
impl_scalar_type * getRawPtr() const
Raw pointer to the MultiVector&#39;s data.
Tpetra::Map< LO, GO, Node > map_type
The specialization of Tpetra::Map that this class uses.
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.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
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.
size_t getStrideY() const
Stride between consecutive local entries in the same row.
virtual bool checkSizes(const Tpetra::SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
One or more distributed dense vectors.
Forward declaration of Tpetra::Experimental::BlockMultiVector.
MultiVector for multiple degrees of freedom per mesh point.
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.
int local_ordinal_type
Default value of Scalar template parameter.
size_t getNumVectors() const
Number of columns in the multivector.
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.
mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
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.
Linear algebra kernels for small dense matrices and vectors.
void modify()
Mark data as modified on the given memory space.
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.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
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. ...
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using a global index.
Abstract base class for objects that can be the source of an Import or Export operation.
void sync()
Update data to the given target memory space, only if data in the "other" space have been marked as m...
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
::Kokkos::Details::ArithTraits< Packet >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on the calling process.
size_t getStride() const
Stride between columns in the multivector.
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...
A parallel distribution of indices over processes.
size_t getStrideX() const
Stride between consecutive local entries in the same column.
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 .
map_type getPointMap() const
Get this BlockMultiVector&#39;s (previously computed) point Map.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
mv_type mv_
The Tpetra::MultiVector used to represent the data.
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.