41 #ifndef TPETRA_BLOCKCRSMATRIX_DECL_HPP
42 #define TPETRA_BLOCKCRSMATRIX_DECL_HPP
47 #include "Tpetra_CrsGraph.hpp"
48 #include "Tpetra_RowMatrix.hpp"
49 #include "Tpetra_BlockMultiVector_decl.hpp"
52 #include "KokkosSparse_BsrMatrix.hpp"
56 template<
class BlockCrsMatrixType>
57 Teuchos::RCP<BlockCrsMatrixType>
58 importAndFillCompleteBlockCrsMatrix (
const Teuchos::RCP<const BlockCrsMatrixType>& sourceMatrix,
59 const Import<
typename BlockCrsMatrixType::local_ordinal_type,
60 typename BlockCrsMatrixType::global_ordinal_type,
61 typename BlockCrsMatrixType::node_type>& importer);
62 template<
class BlockCrsMatrixType>
63 Teuchos::RCP<BlockCrsMatrixType>
64 exportAndFillCompleteBlockCrsMatrix (
const Teuchos::RCP<const BlockCrsMatrixType>& sourceMatrix,
65 const Export<
typename BlockCrsMatrixType::local_ordinal_type,
66 typename BlockCrsMatrixType::global_ordinal_type,
67 typename BlockCrsMatrixType::node_type>& exporter);
149 #if defined(TPETRA_ENABLE_BLOCKCRS_LITTLEBLOCK_LAYOUTLEFT)
156 template<
class Scalar,
167 using STS = Teuchos::ScalarTraits<Scalar>;
208 typedef ::Tpetra::MultiVector<Scalar, LO, GO, node_type>
mv_type;
216 Kokkos::MemoryTraits<Kokkos::Unmanaged> >
218 typedef typename little_block_type::HostMirror little_block_host_type;
224 Kokkos::MemoryTraits<Kokkos::Unmanaged> >
228 typedef typename BMV::little_host_vec_type little_host_vec_type;
232 typedef typename BMV::const_little_host_vec_type const_host_little_vec_type;
235 using local_inds_device_view_type =
236 typename row_matrix_type::local_inds_device_view_type;
237 using local_inds_host_view_type =
238 typename row_matrix_type::local_inds_host_view_type;
239 using nonconst_local_inds_host_view_type =
240 typename row_matrix_type::nonconst_local_inds_host_view_type;
242 using global_inds_device_view_type =
243 typename row_matrix_type::global_inds_device_view_type;
244 using global_inds_host_view_type =
245 typename row_matrix_type::global_inds_host_view_type;
246 using nonconst_global_inds_host_view_type =
247 typename row_matrix_type::nonconst_global_inds_host_view_type;
249 using values_device_view_type =
250 typename row_matrix_type::values_device_view_type;
251 using values_host_view_type =
252 typename row_matrix_type::values_host_view_type;
253 using nonconst_values_host_view_type =
254 typename row_matrix_type::nonconst_values_host_view_type;
258 using local_matrix_device_type =
263 typename local_graph_device_type::size_type>;
264 using local_matrix_host_type =
265 typename local_matrix_device_type::HostMirror;
286 const typename local_matrix_device_type::values_type& values,
309 Teuchos::RCP<const map_type>
getDomainMap ()
const override;
312 Teuchos::RCP<const map_type>
getRangeMap ()
const override;
315 Teuchos::RCP<const map_type>
getRowMap ()
const override;
318 Teuchos::RCP<const map_type>
getColMap ()
const override;
340 Teuchos::ETransp mode = Teuchos::NO_TRANS,
341 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one (),
342 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero ())
const override;
386 describe (Teuchos::FancyOStream& out,
387 const Teuchos::EVerbosityLevel verbLevel)
const override;
397 virtual Teuchos::RCP<const ::Tpetra::RowGraph<LO,GO,Node> >
getGraph ()
const override;
406 applyBlock (
const BlockMultiVector<Scalar, LO, GO, Node>& X,
407 BlockMultiVector<Scalar, LO, GO, Node>& Y,
408 Teuchos::ETransp mode = Teuchos::NO_TRANS,
409 const Scalar alpha = Teuchos::ScalarTraits<Scalar>::one (),
410 const Scalar beta = Teuchos::ScalarTraits<Scalar>::zero ());
416 const Import<LO, GO, Node>& importer)
const;
422 const Export<LO, GO, Node>& exporter)
const;
455 const LO numColInds)
const;
487 const LO numColInds)
const;
524 local_inds_host_view_type &indices,
525 values_host_view_type &values)
const override;
531 local_inds_host_view_type &indices,
532 nonconst_values_host_view_type &values)
const;
537 nonconst_local_inds_host_view_type &Indices,
538 nonconst_values_host_view_type &Values,
539 size_t& NumEntries)
const override;
541 getLocalBlockDeviceNonConst (
const LO localRowInd,
const LO localColInd)
const;
543 little_block_host_type
544 getLocalBlockHostNonConst (
const LO localRowInd,
const LO localColInd)
const;
574 const LO numColInds)
const;
583 const ptrdiff_t offsets[],
585 const LO numOffsets)
const;
588 absMaxLocalValuesByOffsets (
const LO localRowInd,
589 const ptrdiff_t offsets[],
591 const LO numOffsets)
const;
600 const ptrdiff_t offsets[],
602 const LO numOffsets)
const;
652 return (*errs_).is_null () ? std::string (
"") : (*errs_)->str ();
688 Kokkos::MemoryUnmanaged>& offsets)
const;
706 Kokkos::MemoryUnmanaged>& diag,
708 Kokkos::MemoryUnmanaged>& offsets)
const;
729 const LO numColInds)
const;
745 virtual bool checkSizes (const ::Tpetra::SrcDistObject& source)
override;
756 const size_t numSameIDs,
777 Kokkos::DualView<
size_t*,
779 size_t& constantNumPackets)
override;
794 Kokkos::DualView<
size_t*,
796 const size_t constantNumPackets,
803 Teuchos::RCP<crs_graph_type> graphRCP_;
843 using graph_row_offset_host_type =
typename crs_graph_type::local_graph_device_type::row_map_type::HostMirror;
844 graph_row_offset_host_type ptrHost_;
851 using graph_column_indices_host_type =
typename crs_graph_type::local_graph_device_type::entries_type::HostMirror;
852 graph_column_indices_host_type indHost_;
859 using impl_scalar_type_dualview = Kokkos::DualView<impl_scalar_type*, device_type>;
884 Teuchos::RCP<Teuchos::RCP<BMV> > X_colMap_;
888 Teuchos::RCP<Teuchos::RCP<BMV> > Y_rowMap_;
897 Teuchos::RCP<Teuchos::RCP<typename crs_graph_type::import_type> > pointImporter_;
913 Teuchos::RCP<bool> localError_;
922 Teuchos::RCP<Teuchos::RCP<std::ostringstream> > errs_;
925 std::ostream& markLocalErrorAndGetStream ();
930 template<
class Device>
932 #if defined(KOKKOS_ENABLE_CUDA)
938 static constexpr
bool value =
939 std::is_same<typename Device::execution_space, Kokkos::Cuda>::value;
941 #elif defined(KOKKOS_ENABLE_HIP)
942 static constexpr
bool value =
943 std::is_same<typename Device::execution_space, Kokkos::HIP>::value;
944 #elif defined(KOKKOS_ENABLE_SYCL)
945 static constexpr
bool value =
946 std::is_same<typename Device::execution_space, Kokkos::Experimental::SYCL>::value;
948 static constexpr
bool value =
false;
953 typename impl_scalar_type_dualview::t_host::const_type
954 getValuesHost()
const;
956 typename impl_scalar_type_dualview::t_dev::const_type
957 getValuesDevice()
const;
977 typename impl_scalar_type_dualview::t_host
980 typename impl_scalar_type_dualview::t_dev
981 getValuesDeviceNonConst()
const;
984 typename impl_scalar_type_dualview::t_host::const_type
985 getValuesHost (
const LO& lclRow)
const;
988 typename impl_scalar_type_dualview::t_dev::const_type
989 getValuesDevice (
const LO& lclRow)
const;
992 typename impl_scalar_type_dualview::t_host
996 typename impl_scalar_type_dualview::t_dev
997 getValuesDeviceNonConst (
const LO& lclRow);
1014 const Teuchos::ETransp mode,
1084 findRelOffsetOfColumnIndex (
const LO localRowIndex,
1085 const LO colIndexToFind,
1086 const LO hint = 0)
const;
1090 LO offsetPerBlock ()
const;
1093 getConstLocalBlockFromInput (
const impl_scalar_type* val,
const size_t pointOffset)
const;
1096 getNonConstLocalBlockFromInput (
impl_scalar_type* val,
const size_t pointOffset)
const;
1098 little_block_host_type
1099 getNonConstLocalBlockFromInputHost (
impl_scalar_type* val,
const size_t pointOffset)
const;
1106 virtual Teuchos::RCP<const Teuchos::Comm<int> >
getComm()
const override;
1137 virtual bool hasColMap ()
const override;
1194 nonconst_global_inds_host_view_type &Indices,
1195 nonconst_values_host_view_type &Values,
1196 size_t& NumEntries)
const override;
1223 global_inds_host_view_type & indices,
1224 values_host_view_type & values)
const override;
1248 virtual void leftScale (const ::Tpetra::Vector<Scalar, LO, GO, Node>& x)
override;
1255 virtual void rightScale (const ::Tpetra::Vector<Scalar, LO, GO, Node>& x)
override;
1265 virtual typename ::Tpetra::RowMatrix<Scalar, LO, GO, Node>::mag_type
1270 template<
class BlockCrsMatrixType>
1271 friend Teuchos::RCP<BlockCrsMatrixType>
1272 Tpetra::importAndFillCompleteBlockCrsMatrix (
const Teuchos::RCP<const BlockCrsMatrixType>& sourceMatrix,
1273 const Import<
typename BlockCrsMatrixType::local_ordinal_type,
1274 typename BlockCrsMatrixType::global_ordinal_type,
1275 typename BlockCrsMatrixType::node_type>& importer);
1277 template<
class BlockCrsMatrixType>
1278 friend Teuchos::RCP<BlockCrsMatrixType>
1279 Tpetra::exportAndFillCompleteBlockCrsMatrix (
const Teuchos::RCP<const BlockCrsMatrixType>& sourceMatrix,
1280 const Export<
typename BlockCrsMatrixType::local_ordinal_type,
1281 typename BlockCrsMatrixType::global_ordinal_type,
1282 typename BlockCrsMatrixType::node_type>& exporter);
1286 template<
class BlockCrsMatrixType>
1287 Teuchos::RCP<BlockCrsMatrixType>
1288 importAndFillCompleteBlockCrsMatrix (
const Teuchos::RCP<const BlockCrsMatrixType>& sourceMatrix,
1289 const Import<
typename BlockCrsMatrixType::local_ordinal_type,
1290 typename BlockCrsMatrixType::global_ordinal_type,
1291 typename BlockCrsMatrixType::node_type>& importer)
1293 Teuchos::RCP<BlockCrsMatrixType> destMatrix;
1294 sourceMatrix->importAndFillComplete (destMatrix, importer);
1299 template<
class BlockCrsMatrixType>
1300 Teuchos::RCP<BlockCrsMatrixType>
1301 exportAndFillCompleteBlockCrsMatrix (
const Teuchos::RCP<const BlockCrsMatrixType>& sourceMatrix,
1302 const Export<
typename BlockCrsMatrixType::local_ordinal_type,
1303 typename BlockCrsMatrixType::global_ordinal_type,
1304 typename BlockCrsMatrixType::node_type>& exporter)
1306 Teuchos::RCP<BlockCrsMatrixType> destMatrix;
1307 sourceMatrix->exportAndFillComplete (destMatrix, exporter);
1313 #endif // TPETRA_BLOCKCRSMATRIX_DECL_HPP
virtual void getLocalRowCopy(LO LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Not implemented.
size_t getNumEntriesInLocalRow(const LO localRowInd) const override
Return the number of entries in the given row on the calling process.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
virtual size_t getLocalNumEntries() const override
The local number of stored (structurally nonzero) entries.
virtual global_size_t getGlobalNumCols() const override
The global number of columns of this matrix.
::Tpetra::MultiVector< Scalar, LO, GO, node_type > mv_type
The implementation of MultiVector that this class uses.
Kokkos::View< const impl_scalar_type *, device_type > const_little_vec_type
"Const block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector...
typename BMV::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
void getLocalDiagCopy(const Kokkos::View< impl_scalar_type ***, device_type, Kokkos::MemoryUnmanaged > &diag, const Kokkos::View< const size_t *, device_type, Kokkos::MemoryUnmanaged > &offsets) const
Variant of getLocalDiagCopy() that uses precomputed offsets and puts diagonal blocks in a 3-D Kokkos:...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
Print a description of this object to the given output stream.
Kokkos::View< impl_scalar_type **, Impl::BlockCrsMatrixLittleBlockArrayLayout, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > little_block_type
The type used to access nonconst matrix blocks.
virtual typename::Tpetra::RowMatrix< Scalar, LO, GO, Node >::mag_type getFrobeniusNorm() const override
The Frobenius norm of the matrix.
LO replaceLocalValues(const LO localRowInd, const LO colInds[], const Scalar vals[], const LO numColInds) const
Replace values at the given (mesh, i.e., block) column indices, in the given (mesh, i.e., block) row.
virtual void leftScale(const ::Tpetra::Vector< Scalar, LO, GO, Node > &x) override
Scale the RowMatrix on the left with the given Vector x.
virtual LO getBlockSize() const override
The number of degrees of freedom per mesh point.
LO replaceLocalValuesByOffsets(const LO localRowInd, const ptrdiff_t offsets[], const Scalar vals[], const LO numOffsets) const
Like replaceLocalValues, but avoids computing row offsets.
std::string description() const override
One-line description of this object.
Sparse matrix whose entries are small dense square blocks, all of the same dimensions.
typename DistObject< Scalar, LO, GO, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
void exportAndFillComplete(Teuchos::RCP< BlockCrsMatrix< Scalar, LO, GO, Node > > &destMatrix, const Export< LO, GO, Node > &exporter) const
Import from this to the given destination matrix, and make the result fill complete.
virtual bool hasColMap() const override
Whether this matrix has a well-defined column 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)
Perform copies and permutations that are local to the calling (MPI) process.
virtual bool isLocallyIndexed() const override
Whether matrix indices are locally indexed.
bool hasTransposeApply() const override
Whether it is valid to apply the transpose or conjugate transpose of this matrix. ...
LO local_ordinal_type
The type of local indices.
void getLocalRowViewNonConst(LO LocalRow, local_inds_host_view_type &indices, nonconst_values_host_view_type &values) const
::Tpetra::CrsGraph< LO, GO, node_type > crs_graph_type
The implementation of CrsGraph that this class uses.
Kokkos::View< impl_scalar_type *, device_type > little_vec_type
"Block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
Node node_type
The Node type.
Kokkos::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, device_type, void, size_t > local_graph_device_type
The type of the part of the sparse graph on each MPI process.
bool localError() const
Whether this object had an error on the calling process.
Declaration of the Tpetra::CrsMatrix class.
Scalar scalar_type
The type of entries in the matrix (that is, of each entry in each block).
size_t getLocalNumRows() const override
get the local number of block rows
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.
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which this matrix is distributed.
Kokkos::LayoutRight BlockCrsMatrixLittleBlockArrayLayout
give an option to use layoutleft
virtual void rightScale(const ::Tpetra::Vector< Scalar, LO, GO, Node > &x) override
Scale the RowMatrix on the right with the given Vector x.
::Tpetra::Map< LO, GO, node_type > map_type
The implementation of Map that this class uses.
void getLocalRowView(LO LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const override
Get a view of the (mesh, i.e., block) row, using local (mesh, i.e., block) indices.
virtual ~BlockCrsMatrix()
Destructor (declared virtual for memory safety).
MultiVector for multiple degrees of freedom per mesh point.
virtual void copyAndPermute(const SrcDistObject &sourceObj, 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
Teuchos::RCP< const map_type > getColMap() const override
get the (mesh) map for the columns of this block matrix.
GO global_ordinal_type
The type of global indices.
virtual size_t getGlobalMaxNumRowEntries() const override
The maximum number of entries in any row over all processes in the matrix's communicator.
size_t global_size_t
Global size_t object.
virtual void getGlobalRowView(GO GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant, nonpersisting, globally indexed view of the given row of the matrix.
BlockCrsMatrix()
Default constructor: Makes an empty block matrix.
LO absMaxLocalValues(const LO localRowInd, const LO colInds[], const Scalar vals[], const LO numColInds) const
Variant of getLocalDiagCopy() that uses precomputed offsets and puts diagonal blocks in a 3-D Kokkos:...
Teuchos::RCP< const map_type > getDomainMap() const override
Get the (point) domain Map of this matrix.
device_type::memory_space memory_space
The Kokkos memory space that this class uses.
Teuchos::RCP< const map_type > getRowMap() const override
get the (mesh) map for the rows of this block matrix.
std::string errorMessages() const
The current stream of error messages.
LO sumIntoLocalValuesByOffsets(const LO localRowInd, const ptrdiff_t offsets[], const Scalar vals[], const LO numOffsets) const
Like sumIntoLocalValues, but avoids computing row offsets.
global_size_t getGlobalNumRows() const override
get the global number of block rows
BMV::const_little_vec_type const_little_vec_type
The type used to access const vector blocks.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
virtual Teuchos::RCP< const ::Tpetra::RowGraph< LO, GO, Node > > getGraph() const override
Get the (mesh) graph.
virtual GO getIndexBase() const override
The index base for global indices in this matrix.
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).
Kokkos::View< const impl_scalar_type **, Impl::BlockCrsMatrixLittleBlockArrayLayout, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > const_little_block_type
The type used to access const matrix blocks.
void applyBlock(const BlockMultiVector< Scalar, LO, GO, Node > &X, BlockMultiVector< Scalar, LO, GO, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, const Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), const Scalar beta=Teuchos::ScalarTraits< Scalar >::zero())
Version of apply() that takes BlockMultiVector input and output.
CombineMode
Rule for combining data in an Import or Export.
virtual bool isGloballyIndexed() const override
Whether matrix indices are globally indexed.
LO getLocalRowOffsets(const LO localRowInd, ptrdiff_t offsets[], const LO colInds[], const LO numColInds) const
Get relative offsets corresponding to the given rows, given by local row index.
size_t getLocalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
virtual global_size_t getGlobalNumEntries() const override
The global number of stored (structurally nonzero) entries.
void apply(const mv_type &X, mv_type &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
For this matrix A, compute Y := beta * Y + alpha * Op(A) * X.
Abstract base class for objects that can be the source of an Import or Export operation.
device_type::execution_space execution_space
The Kokkos execution space that this class uses.
Teuchos::RCP< const map_type > getRangeMap() const override
Get the (point) range Map of this matrix.
void getLocalDiagOffsets(const Kokkos::View< size_t *, device_type, Kokkos::MemoryUnmanaged > &offsets) const
Get offsets of the diagonal entries in the matrix.
char packet_type
Implementation detail; tells.
local_matrix_device_type getLocalMatrixDevice() const
A read-only, row-oriented interface to a sparse matrix.
A distributed dense vector.
virtual bool supportsRowViews() const override
Whether this object implements getLocalRowView() and getGlobalRowView().
virtual void packAndPrepare(const SrcDistObject &sourceObj, 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
BMV::little_vec_type little_vec_type
The type used to access nonconst vector blocks.
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 getGlobalRowCopy(GO GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Get a copy of the given global row's entries.
Node::device_type device_type
The Kokkos::Device specialization that this class uses.
virtual bool isFillComplete() const override
Whether fillComplete() has been called.
impl_scalar_type_dualview::t_host getValuesHostNonConst() const
Get the host or device View of the matrix's values (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.
LO sumIntoLocalValues(const LO localRowInd, const LO colInds[], const Scalar vals[], const LO numColInds) const
Sum into values at the given (mesh, i.e., block) column indices, in the given (mesh, i.e., block) row.
virtual size_t getLocalNumCols() const override
The number of columns needed to apply the forward operator on this node.
void importAndFillComplete(Teuchos::RCP< BlockCrsMatrix< Scalar, LO, GO, Node > > &destMatrix, const Import< LO, GO, Node > &importer) const
Import from this to the given destination matrix, and make the result fill complete.
virtual size_t getNumEntriesInGlobalRow(GO globalRow) const override
The current number of entries on the calling process in the specified global row. ...