Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_BlockMultiVector_decl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // clang-format off
11 #ifndef TPETRA_BLOCKMULTIVECTOR_DECL_HPP
12 #define TPETRA_BLOCKMULTIVECTOR_DECL_HPP
13 
16 #include "Tpetra_MultiVector.hpp"
17 #include <memory>
18 #include <utility>
19 
20 namespace Tpetra {
21 
106 template<class Scalar,
107  class LO,
108  class GO,
109  class Node>
111  public Tpetra::DistObject<Scalar, LO, GO, Node>
112 {
113 private:
115  using STS = Teuchos::ScalarTraits<Scalar>;
116  using packet_type = typename dist_object_type::packet_type;
117 
118 public:
120 
121 
126 
128  using scalar_type = Scalar;
136  using local_ordinal_type = LO;
141 
143  using node_type = Node;
144 
147 
163  typedef Kokkos::View<impl_scalar_type *, device_type> little_vec_type;
164  typedef typename little_vec_type::HostMirror little_host_vec_type;
165 
171  typedef Kokkos::View<const impl_scalar_type *, device_type>
173 
175  host_device_type;
176  typedef Kokkos::View<const impl_scalar_type*, host_device_type>
177  const_little_host_vec_type;
178 
180 
182 
187  BlockMultiVector ();
188 
191 
194 
198 
202 
205  const Teuchos::DataAccess copyOrView);
206 
237  BlockMultiVector (const map_type& meshMap,
238  const LO blockSize,
239  const LO numVecs);
240 
245  BlockMultiVector (const map_type& meshMap,
246  const map_type& pointMap,
247  const LO blockSize,
248  const LO numVecs);
249 
262  BlockMultiVector (const mv_type& X_mv,
263  const map_type& meshMap,
264  const LO blockSize);
265 
271  const map_type& newMeshMap,
272  const map_type& newPointMap,
273  const size_t offset = 0);
274 
280  const map_type& newMeshMap,
281  const size_t offset = 0);
282 
284 
286 
294  static map_type
295  makePointMap (const map_type& meshMap, const LO blockSize);
296 
303  static Teuchos::RCP<const map_type>
304  makePointMapRCP (const map_type& meshMap, const LO blockSize);
305 
310  const map_type getPointMap () const {
311  return *pointMap_;
312  }
313 
315  LO getBlockSize () const {
316  return blockSize_;
317  }
318 
320  LO getNumVectors () const {
321  return static_cast<LO> (mv_.getNumVectors ());
322  }
323 
329  const mv_type & getMultiVectorView () const;
331 
333 
335 
337  void putScalar (const Scalar& val);
338 
340  void scale (const Scalar& val);
341 
348  void
349  update (const Scalar& alpha,
351  const Scalar& beta);
352 
374  void
375  blockWiseMultiply (const Scalar& alpha,
376  const Kokkos::View<const impl_scalar_type***,
377  device_type, Kokkos::MemoryUnmanaged>& D,
379 
410  void
411  blockJacobiUpdate (const Scalar& alpha,
412  const Kokkos::View<const impl_scalar_type***,
413  device_type, Kokkos::MemoryUnmanaged>& D,
416  const Scalar& beta);
417 
418 
420  template<class TargetMemorySpace>
421  bool need_sync () const {
422  return mv_.template need_sync<typename TargetMemorySpace::memory_space> ();
423  }
424 
426  bool need_sync_host() const {
427  return mv_.need_sync_host();
428  }
429 
431  bool need_sync_device() const {
432  return mv_.need_sync_device();
433  }
434 
436 
438 
456  bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]);
457 
468  bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
469 
480  bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]);
481 
492  bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
493 
494 
495  const_little_host_vec_type getLocalBlockHost(
496  const LO localRowIndex,
497  const LO colIndex,
498  const Access::ReadOnlyStruct) const;
499 
500  little_host_vec_type getLocalBlockHost(
501  const LO localRowIndex,
502  const LO colIndex,
503  const Access::ReadWriteStruct);
504 
508  little_host_vec_type getLocalBlockHost(
509  const LO localRowIndex,
510  const LO colIndex,
511  const Access::OverwriteAllStruct);
513 
514 protected:
520 
521 
522  // clang-format on
523  virtual bool checkSizes(const Tpetra::SrcDistObject &source) override;
524 
525  using dist_object_type::
527  // clang-format off
529 
530  virtual void
532  (const SrcDistObject& source,
533  const size_t numSameIDs,
534  const Kokkos::DualView<const local_ordinal_type*,
535  buffer_device_type>& permuteToLIDs,
536  const Kokkos::DualView<const local_ordinal_type*,
537  buffer_device_type>& permuteFromLIDs,
538  const CombineMode CM) override;
539 
541  // clang-format off
545 
546  virtual void
548  (const SrcDistObject& source,
549  const Kokkos::DualView<const local_ordinal_type*,
550  buffer_device_type>& exportLIDs,
551  Kokkos::DualView<packet_type*,
552  buffer_device_type>& exports,
553  Kokkos::DualView<size_t*,
554  buffer_device_type> numPacketsPerLID,
555  size_t& constantNumPackets) override;
556 
558  // clang-format off
562 
563  virtual void
565  (const Kokkos::DualView<const local_ordinal_type*,
566  buffer_device_type>& importLIDs,
567  Kokkos::DualView<packet_type*,
568  buffer_device_type> imports,
569  Kokkos::DualView<size_t*,
570  buffer_device_type> numPacketsPerLID,
571  const size_t constantNumPackets,
572  const CombineMode combineMode) override;
573  // clang-format off
574 
576 
577 protected:
578 
580  size_t getStrideX () const {
581  return static_cast<size_t> (1);
582  }
583 
585  size_t getStrideY () const {
586  return mv_.getStride ();
587  }
588 
591  bool isValidLocalMeshIndex (const LO meshLocalIndex) const;
592 
599 
600 private:
602  Teuchos::RCP<const map_type> pointMap_;
603 
604 protected:
607 
608 private:
609 
611  LO blockSize_;
612 
614  void
615  replaceLocalValuesImpl (const LO localRowIndex,
616  const LO colIndex,
617  const Scalar vals[]);
619  void
620  sumIntoLocalValuesImpl (const LO localRowIndex,
621  const LO colIndex,
622  const Scalar vals[]);
623 
624  static Teuchos::RCP<const mv_type>
625  getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
626 
627  static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
628  getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
629 };
630 
631 } // namespace Tpetra
632 
633 #endif // TPETRA_BLOCKMULTIVECTOR_DECL_HPP
Node node_type
The Kokkos Node type; a legacy thing that will go away at some point.
BlockMultiVector< Scalar, LO, GO, Node > & operator=(const BlockMultiVector< Scalar, LO, GO, Node > &)=default
Copy assigment (shallow copy).
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
Kokkos::View< const impl_scalar_type *, device_type > const_little_vec_type
&quot;Const block view&quot; of all degrees of freedom at a mesh point, for a single column of the MultiVector...
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM)
Perform copies and permutations that are local to the calling (MPI) process.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
bool need_sync_device() const
Whether this object needs synchronization to the device.
LO local_ordinal_type
The type of local indices.
size_t getNumVectors() const
Number of columns in the multivector.
typename::Kokkos::ArithTraits< Scalar >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
typename map_type::device_type device_type
This class&#39; preferred Kokkos device type.
Kokkos::View< impl_scalar_type *, device_type > little_vec_type
&quot;Block view&quot; of all degrees of freedom at a mesh point, for a single column of the MultiVector...
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.
size_t getStrideX() const
Stride between consecutive local entries in the same column.
const map_type getPointMap() const
Get this BlockMultiVector&#39;s (previously computed) point Map.
Forward declaration of Tpetra::BlockCrsMatrix.
GO global_ordinal_type
The type of global indices.
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Replace all values at the given mesh point, using a global index.
static Teuchos::RCP< const map_type > makePointMapRCP(const map_type &meshMap, const LO blockSize)
Create and return an owning RCP to the point Map corresponding to the given mesh Map and block size...
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode)
Perform any unpacking and combining after communication.
size_t getStrideY() const
Stride between consecutive local entries in the same row.
bool replaceLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[])
Replace all values at the given mesh point, using local row and column indices.
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.
bool sumIntoLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[])
Sum into all values at the given mesh point, using a local index.
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
MultiVector for multiple degrees of freedom per mesh point.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
virtual bool checkSizes(const Tpetra::SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
bool need_sync_host() const
Whether this object needs synchronization to the host.
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
const mv_type & getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector&#39;s data.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode) override
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets)
Pack data and metadata for communication (sends).
typename mv_type::device_type device_type
The Kokkos Device type.
CombineMode
Rule for combining data in an Import or Export.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Sum into all values at the given mesh point, using a global index.
bool need_sync_host() const
Whether this MultiVector needs synchronization to the host.
mv_type mv_
The Tpetra::MultiVector used to represent the data.
Abstract base class for objects that can be the source of an Import or Export operation.
Forward declaration of Tpetra::BlockMultiVector.
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM) override
Scalar scalar_type
The type of entries in the object.
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.
typename dist_object_type::buffer_device_type buffer_device_type
Kokkos::Device specialization used for communication buffers.
size_t getStride() const
Stride between columns in the multivector.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
Base class for distributed Tpetra objects that support data redistribution.
typename mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the object.
map_type meshMap_
Mesh Map given to constructor.
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets) override