Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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#ifndef TPETRA_BLOCKMULTIVECTOR_DECL_HPP
11#define TPETRA_BLOCKMULTIVECTOR_DECL_HPP
12
15#include "Tpetra_MultiVector.hpp"
16#include <memory>
17#include <utility>
18
19namespace Tpetra {
20
105template <class Scalar,
106 class LO,
107 class GO,
108 class Node>
109class BlockMultiVector : public Tpetra::DistObject<Scalar, LO, GO, Node> {
110 private:
111 using dist_object_type = Tpetra::DistObject<Scalar, LO, GO, Node>;
112 using STS = Teuchos::ScalarTraits<Scalar>;
113 using packet_type = typename dist_object_type::packet_type;
114
115 public:
117
118
123
125 using scalar_type = Scalar;
138
140 using node_type = Node;
141
144
160 typedef Kokkos::View<impl_scalar_type*, device_type> little_vec_type;
161 typedef typename little_vec_type::host_mirror_type little_host_vec_type;
162
168 typedef Kokkos::View<const impl_scalar_type*, device_type>
170
172 host_device_type;
173 typedef Kokkos::View<const impl_scalar_type*, host_device_type>
174 const_little_host_vec_type;
175
177
179
185
188
191
195
199
202 const Teuchos::DataAccess copyOrView);
203
235 const LO blockSize,
236 const LO numVecs);
237
243 const map_type& pointMap,
244 const LO blockSize,
245 const LO numVecs);
246
260 const map_type& meshMap,
261 const LO blockSize);
262
268 const map_type& newMeshMap,
269 const map_type& newPointMap,
270 const size_t offset = 0);
271
277 const map_type& newMeshMap,
278 const size_t offset = 0);
279
281
283
291 static map_type
292 makePointMap(const map_type& meshMap, const LO blockSize);
293
300 static Teuchos::RCP<const map_type>
301 makePointMapRCP(const map_type& meshMap, const LO blockSize);
302
307 const map_type getPointMap() const {
308 return *pointMap_;
309 }
310
312 LO getBlockSize() const {
313 return blockSize_;
314 }
315
317 LO getNumVectors() const {
318 return static_cast<LO>(mv_.getNumVectors());
319 }
320
328
330
332
334 void putScalar(const Scalar& val);
335
337 void scale(const Scalar& val);
338
345 void
346 update(const Scalar& alpha,
348 const Scalar& beta);
349
370 void
371 blockWiseMultiply(const Scalar& alpha,
372 const Kokkos::View<const impl_scalar_type***,
373 device_type, Kokkos::MemoryUnmanaged>& D,
375
406 void
407 blockJacobiUpdate(const Scalar& alpha,
408 const Kokkos::View<const impl_scalar_type***,
409 device_type, Kokkos::MemoryUnmanaged>& D,
412 const Scalar& beta);
413
415 template <class TargetMemorySpace>
416 bool need_sync() const {
418 }
419
421 bool need_sync_host() const {
422 return mv_.need_sync_host();
423 }
424
426 bool need_sync_device() const {
427 return mv_.need_sync_device();
428 }
429
431
433
451 bool replaceLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[]);
452
463 bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
464
475 bool sumIntoLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[]);
476
487 bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
488
489 const_little_host_vec_type getLocalBlockHost(
490 const LO localRowIndex,
491 const LO colIndex,
492 const Access::ReadOnlyStruct) const;
493
494 little_host_vec_type getLocalBlockHost(
495 const LO localRowIndex,
496 const LO colIndex,
497 const Access::ReadWriteStruct);
498
502 little_host_vec_type getLocalBlockHost(
503 const LO localRowIndex,
504 const LO colIndex,
505 const Access::OverwriteAllStruct);
507
508 protected:
514
515
516 virtual bool checkSizes(const Tpetra::SrcDistObject& source) override;
517
518 using dist_object_type::
519 copyAndPermute;
521
522 virtual void
524 const size_t numSameIDs,
525 const Kokkos::DualView<const local_ordinal_type*,
526 buffer_device_type>& permuteToLIDs,
527 const Kokkos::DualView<const local_ordinal_type*,
528 buffer_device_type>& permuteFromLIDs,
529 const CombineMode CM) override;
530
535
536 virtual void
538 const Kokkos::DualView<const local_ordinal_type*,
539 buffer_device_type>& exportLIDs,
540 Kokkos::DualView<packet_type*,
541 buffer_device_type>& exports,
542 Kokkos::DualView<size_t*,
544 numPacketsPerLID,
545 size_t& constantNumPackets) override;
546
551
552 virtual void
553 unpackAndCombine(const Kokkos::DualView<const local_ordinal_type*,
554 buffer_device_type>& importLIDs,
555 Kokkos::DualView<packet_type*,
557 imports,
558 Kokkos::DualView<size_t*,
560 numPacketsPerLID,
561 const size_t constantNumPackets,
562 const CombineMode combineMode) override;
563
565
566 protected:
568 size_t getStrideX() const {
569 return static_cast<size_t>(1);
570 }
571
573 size_t getStrideY() const {
574 return mv_.getStride();
575 }
576
579 bool isValidLocalMeshIndex(const LO meshLocalIndex) const;
580
587
588 private:
590 Teuchos::RCP<const map_type> pointMap_;
591
592 protected:
595
596 private:
598 LO blockSize_;
599
601 void
602 replaceLocalValuesImpl(const LO localRowIndex,
603 const LO colIndex,
604 const Scalar vals[]);
606 void
607 sumIntoLocalValuesImpl(const LO localRowIndex,
608 const LO colIndex,
609 const Scalar vals[]);
610
611 static Teuchos::RCP<const mv_type>
612 getMultiVectorFromSrcDistObject(const Tpetra::SrcDistObject&);
613
614 static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
615 getBlockMultiVectorFromSrcDistObject(const Tpetra::SrcDistObject& src);
616};
617
618} // namespace Tpetra
619
620#endif // TPETRA_BLOCKMULTIVECTOR_DECL_HPP
Forward declaration of Tpetra::BlockCrsMatrix.
Forward declaration of Tpetra::BlockMultiVector.
virtual bool checkSizes(const Tpetra::SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
const mv_type & getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector's data.
BlockMultiVector(BlockMultiVector< Scalar, LO, GO, Node > &&)=default
Move constructor (shallow move).
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.
BlockMultiVector< Scalar, LO, GO, Node > & operator=(BlockMultiVector< Scalar, LO, GO, Node > &&)=default
Move assigment (shallow move).
bool need_sync_host() const
Whether this object needs synchronization to the host.
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() const
Whether this object needs synchronization to the given memory space.
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.
Kokkos::View< impl_scalar_type *, device_type > little_vec_type
BlockMultiVector(const map_type &meshMap, const LO blockSize, const LO numVecs)
Constructor that takes a mesh Map, a block size, and a number of vectors (columns).
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 .
BlockMultiVector(const BlockMultiVector< Scalar, LO, GO, Node > &)=default
Copy constructor (shallow copy).
BlockMultiVector< Scalar, LO, GO, Node > & operator=(const BlockMultiVector< Scalar, LO, GO, Node > &)=default
Copy assigment (shallow copy).
little_host_vec_type getLocalBlockHost(const LO localRowIndex, const LO colIndex, const Access::OverwriteAllStruct)
Get a local block on host, with the intent to overwrite all blocks in the BlockMultiVector before acc...
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
typename mv_type::impl_scalar_type impl_scalar_type
bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Sum into all values at the given mesh point, using a global index.
BlockMultiVector(const BlockMultiVector< Scalar, LO, GO, Node > &X, const map_type &newMeshMap, const size_t offset=0)
View an existing BlockMultiVector using a different mesh Map; compute the new point Map.
BlockMultiVector(const BlockMultiVector< Scalar, LO, GO, Node > &in, const Teuchos::DataAccess copyOrView)
"Copy constructor" with option to deep copy.
const map_type getPointMap() const
Get this BlockMultiVector's (previously computed) point Map.
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.
typename dist_object_type::buffer_device_type buffer_device_type
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
BlockMultiVector(const BlockMultiVector< Scalar, LO, GO, Node > &X, const map_type &newMeshMap, const map_type &newPointMap, const size_t offset=0)
View an existing BlockMultiVector using a different mesh Map, supplying the corresponding point Map.
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
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
Tpetra::Map< LO, GO, Node > map_type
typename mv_type::device_type device_type
size_t getStrideX() const
Stride between consecutive local entries in the same column.
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
BlockMultiVector(const mv_type &X_mv, const map_type &meshMap, const LO blockSize)
View an existing MultiVector.
Kokkos::View< const impl_scalar_type *, device_type > const_little_vec_type
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
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
bool need_sync_device() const
Whether this object needs synchronization to the device.
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Replace all values at the given mesh point, using a global index.
size_t getStrideY() const
Stride between consecutive local entries in the same row.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
BlockMultiVector(const map_type &meshMap, const map_type &pointMap, const LO blockSize, const LO numVecs)
Constructor that takes a mesh Map, a point Map, a block size, and a number of vectors (columns).
Base class for distributed Tpetra objects that support data redistribution.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
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)
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)
typename ::KokkosKernels::ArithTraits< Scalar >::val_type packet_type
A parallel distribution of indices over processes.
One or more distributed dense vectors.
typename KokkosKernels::ArithTraits< Scalar >::val_type impl_scalar_type
Abstract base class for objects that can be the source of an Import or Export operation.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
CombineMode
Rule for combining data in an Import or Export.