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 
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:
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:
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
Tpetra::Experimental::Classes::BlockMultiVector::scale
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:648
Tpetra::Experimental::Classes::BlockMultiVector::BlockMultiVector
BlockMultiVector()
Default constructor.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:250
Tpetra::Experimental::Classes::BlockMultiVector::sumIntoLocalValues
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:365
Tpetra::Experimental::Classes::BlockMultiVector::getMultiVectorView
mv_type getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector's data.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:104
Tpetra::Experimental::Classes::BlockMultiVector::putScalar
void putScalar(const Scalar &val)
Fill all entries with the given value val.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:641
Tpetra::Experimental::Classes::BlockMultiVector::getNumVectors
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:329
Tpetra::Experimental::Classes::BlockMultiVector::sumIntoGlobalValues
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:380
Tpetra::Experimental::Classes::BlockMultiVector::getRawPtr
impl_scalar_type * getRawPtr() const
Raw pointer to the MultiVector's data.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:602
Tpetra::Experimental::Classes::BlockMultiVector::map_type
Tpetra::Map< LO, GO, Node > map_type
The specialization of Tpetra::Map that this class uses.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:162
Tpetra::Experimental::Classes::BlockMultiVector::blockWiseMultiply
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:848
Tpetra::Experimental::Classes::BlockMultiVector::checkSizes
virtual bool checkSizes(const Tpetra::SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:482
Tpetra::Experimental::Classes::BlockMultiVector::local_ordinal_type
LO local_ordinal_type
The type of local indices.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:175
Tpetra::Details::DefaultTypes::node_type
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
Definition: Tpetra_Details_DefaultTypes.hpp:105
Tpetra::Experimental::Classes::BlockMultiVector::node_type
Node node_type
The Kokkos Node type.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:182
Tpetra::Experimental::Classes::BlockMultiVector::getStrideY
size_t getStrideY() const
Stride between consecutive local entries in the same row.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:612
Tpetra_Experimental_BlockMultiVector_fwd.hpp
Forward declaration of Tpetra::Experimental::BlockMultiVector.
Tpetra::Experimental::Classes::BlockMultiVector::scalar_type
Scalar scalar_type
The type of entries in the matrix.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:167
Tpetra_Experimental_BlockCrsMatrix_fwd.hpp
Forward declaration of Tpetra::Experimental::BlockCrsMatrix.
Tpetra::Experimental::Classes::BlockMultiVector::replaceLocalValues
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:321
Tpetra::Experimental::Classes::BlockMultiVector::mv_type
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:164
Tpetra_Experimental_BlockView.hpp
Linear algebra kernels for small dense matrices and vectors.
Tpetra::Experimental::Classes::BlockMultiVector::getLocalBlock
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:425
Tpetra::Classes::MultiVector::getStride
size_t getStride() const
Stride between columns in the multivector.
Definition: Tpetra_MultiVector_def.hpp:772
Tpetra::Experimental::Classes::BlockMultiVector::impl_scalar_type
mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:173
Tpetra::Experimental::Classes::BlockMultiVector::device_type
Node::device_type device_type
The Kokkos Device type.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:179
Tpetra::Experimental::Classes::BlockMultiVector::getBlockSize
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:324
Tpetra::Experimental::Classes::BlockMultiVector::getGlobalRowView
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:410
Tpetra::Classes::DistObject
Base class for distributed Tpetra objects that support data redistribution.
Definition: Tpetra_DistObject_decl.hpp:349
Tpetra::Experimental::Classes::BlockMultiVector::getLocalRowView
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:396
Tpetra::Experimental::Classes::BlockMultiVector::modify
void modify()
Mark data as modified on the given memory space.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:465
Tpetra::Distributor
Sets up and executes a communication plan for a Tpetra DistObject.
Definition: Tpetra_Distributor.hpp:188
Tpetra::Experimental::Classes::BlockMultiVector::makePointMap
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.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:262
Tpetra::Classes::MultiVector
One or more distributed dense vectors.
Definition: Tpetra_MultiVector_decl.hpp:389
Tpetra::Details::DefaultTypes::local_ordinal_type
int local_ordinal_type
Default value of Scalar template parameter.
Definition: Tpetra_Details_DefaultTypes.hpp:72
Tpetra::Experimental::Classes::BlockMultiVector::replaceGlobalValues
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using a global index.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:336
Tpetra::Experimental::Classes::BlockMultiVector::sync
void sync()
Update data to the given target memory space, only if data in the "other" space have been marked as m...
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:449
Tpetra::Classes::MultiVector::getNumVectors
size_t getNumVectors() const
Number of columns in the multivector.
Definition: Tpetra_MultiVector_def.hpp:1739
Tpetra::Experimental::Classes::BlockMultiVector
MultiVector for multiple degrees of freedom per mesh point.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:147
Tpetra::Classes::Map
A parallel distribution of indices over processes.
Definition: Tpetra_Map_decl.hpp:247
Tpetra::Classes::MultiVector::impl_scalar_type
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Definition: Tpetra_MultiVector_decl.hpp:414
Tpetra::Classes::DistObject::packet_type
::Kokkos::Details::ArithTraits< Packet >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
Definition: Tpetra_DistObject_decl.hpp:361
Tpetra::Experimental::Classes::BlockMultiVector::const_little_vec_type
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.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:214
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Tpetra::Classes::Map::isNodeLocalElement
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on the calling process.
Definition: Tpetra_Map_def.hpp:1134
Tpetra::Experimental::Classes::BlockMultiVector::getPointMap
map_type getPointMap() const
Get this BlockMultiVector's (previously computed) point Map.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:319
Tpetra::Experimental::Classes::BlockMultiVector::update
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:655
Tpetra::SrcDistObject
Abstract base class for objects that can be the source of an Import or Export operation.
Definition: Tpetra_SrcDistObject.hpp:89
Tpetra::Experimental::Classes::BlockMultiVector::getStrideX
size_t getStrideX() const
Stride between consecutive local entries in the same column.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:607
Tpetra::Experimental::Classes::BlockMultiVector::global_ordinal_type
GO global_ordinal_type
The type of global indices.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:177
Tpetra::Experimental::Classes::BlockMultiVector::mv_
mv_type mv_
The Tpetra::MultiVector used to represent the data.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:636
Tpetra::Experimental::Classes::BlockMultiVector::blockJacobiUpdate
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 .
Definition: Tpetra_Experimental_BlockMultiVector_def.hpp:880
Tpetra::Experimental::Classes::BlockMultiVector::little_vec_type
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.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:203
Tpetra::CombineMode
CombineMode
Rule for combining data in an Import or Export.
Definition: Tpetra_CombineMode.hpp:94
Tpetra::Experimental::Classes::BlockMultiVector::need_sync
bool need_sync() const
Whether this object needs synchronization to the given memory space.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:455
Tpetra::Experimental::Classes::BlockMultiVector::isValidLocalMeshIndex
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:618