10#ifndef TPETRA_BLOCKCRSMATRIX_HELPERS_DEF_HPP
11#define TPETRA_BLOCKCRSMATRIX_HELPERS_DEF_HPP
15#include "Tpetra_BlockCrsMatrix.hpp"
16#include "Tpetra_CrsMatrix.hpp"
17#include "Tpetra_HashTable.hpp"
18#include "Tpetra_Import.hpp"
19#include "Tpetra_Map.hpp"
20#include "Tpetra_MultiVector.hpp"
21#include "Teuchos_ParameterList.hpp"
22#include "Teuchos_ScalarTraits.hpp"
28 template<
class Scalar,
class LO,
class GO,
class Node>
30 Teuchos::ParameterList
pl;
36 template<
class Scalar,
class LO,
class GO,
class Node>
43 template<
class Scalar,
class LO,
class GO,
class Node>
45 Teuchos::ParameterList
pl;
49 template<
class Scalar,
class LO,
class GO,
class Node>
55 typedef Teuchos::OrdinalTraits<GO>
TOT;
64 const int myRank = comm->getRank();
65 const size_t numProcs = comm->getSize();
69 if (
params.isParameter(
"always use parallel algorithm"))
72 if (
params.isParameter(
"print MatrixMarket header"))
76 std::time_t
now = std::time(
NULL);
79 Teuchos::ScalarTraits<Scalar>::isComplex ?
"complex" :
"real";
89 os <<
"%%MatrixMarket matrix coordinate " <<
dataTypeStr <<
" general" << std::endl;
91 os <<
"% written from " <<
numProcs <<
" processes" << std::endl;
92 os <<
"% point representation of Tpetra::BlockCrsMatrix" << std::endl;
93 size_t numRows =
A.getGlobalNumRows();
94 size_t numCols =
A.getGlobalNumCols();
95 os <<
"% " <<
numRows <<
" block rows, " << numCols <<
" block columns" << std::endl;
104 size_t numRows = rowMap->getLocalNumElements();
133 std::runtime_error,
"Tpetra::blockCrsMatrixWriter: (pid "
167 template<
class Scalar,
class LO,
class GO,
class Node>
174 using impl_scalar_type =
typename bcrs_type::impl_scalar_type;
176 size_t numRows =
A.getGlobalNumRows();
180 const int myRank = comm->getRank();
185 std::runtime_error,
"Tpetra::writeMatrixStrip: "
186 "mesh row index base != mesh column index base");
191 std::runtime_error,
"Tpetra::writeMatrixStrip: pid "
192 <<
myRank <<
" should have 0 rows but has " <<
A.getLocalNumRows());
194 std::runtime_error,
"Tpetra::writeMatrixStrip: pid "
195 <<
myRank <<
" should have 0 columns but has " <<
A.getLocalNumCols());
200 std::runtime_error,
"Tpetra::writeMatrixStrip: "
201 "number of rows on pid 0 does not match global number of rows");
209 if (
params.isParameter(
"precision")) {
214 if (
params.isParameter(
"zero-based indexing")) {
215 if (
params.get<
bool>(
"zero-based indexing") ==
true)
229 for (LO
k = 0;
k < numEntries; ++
k) {
240 if (Teuchos::ScalarTraits<impl_scalar_type>::isComplex) {
244 << Teuchos::ScalarTraits<impl_scalar_type>::imag (
curVal);
257 std::runtime_error,
"Tpetra::writeMatrixStrip: "
258 "error getting view of local row " <<
localRowInd);
264 template<
class Scalar,
class LO,
class GO,
class Node>
265 Teuchos::RCP<Tpetra::CrsGraph<LO, GO, Node> >
277 using Teuchos::Array;
278 using Teuchos::ArrayView;
285 using local_graph_device_type =
typename crs_matrix_type::local_graph_device_type;
286 using row_map_type =
typename local_graph_device_type::row_map_type::non_const_type;
287 using entries_type =
typename local_graph_device_type::entries_type::non_const_type;
289 using offset_type =
typename row_map_type::non_const_value_type;
291 using execution_space =
typename Node::execution_space;
292 using range_type = Kokkos::RangePolicy<execution_space, LO>;
307 Kokkos::DefaultExecutionSpace().fence();
310 if(
meshColMap.is_null())
throw std::runtime_error(
"ERROR: Cannot create mesh colmap");
327 std::runtime_error,
"Tpetra::getBlockCrsGraph: "
328 "local number of non zero entries is not a multiple of blockSize^2 ");
352 Kokkos::DefaultExecutionSpace().fence();
361 std::runtime_error,
"Tpetra::getBlockCrsGraph: "
362 "local number of non zero entries is not a multiple of blockSize^2 ");
399 Kokkos::DefaultExecutionSpace().fence();
405 template<
class Scalar,
class LO,
class GO,
class Node>
406 Teuchos::RCP<BlockCrsMatrix<Scalar, LO, GO, Node> >
418 using Teuchos::Array;
419 using Teuchos::ArrayView;
425 using local_graph_device_type =
typename crs_matrix_type::local_graph_device_type;
426 using local_matrix_device_type =
typename crs_matrix_type::local_matrix_device_type;
427 using row_map_type =
typename local_graph_device_type::row_map_type::non_const_type;
428 using values_type =
typename local_matrix_device_type::values_type::non_const_type;
430 using offset_type =
typename row_map_type::non_const_value_type;
432 using execution_space =
typename Node::execution_space;
433 using range_type = Kokkos::RangePolicy<execution_space, LO>;
471 Kokkos::DefaultExecutionSpace().fence();
507 offset_type
block_inv=
static_cast<offset_type
>(-1);
517 if (
block_inv!=
static_cast<offset_type
>(-1))
528 Kokkos::DefaultExecutionSpace().fence();
535 template<
class Scalar,
class LO,
class GO,
class Node>
536 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LO, GO, Node>>
540 using execution_space =
typename Node::execution_space;
541 using dev_row_view_t =
typename crs_t::local_graph_device_type::row_map_type::non_const_type;
542 using dev_col_view_t =
typename crs_t::local_graph_device_type::entries_type::non_const_type;
543 using dev_val_view_t =
typename crs_t::local_matrix_device_type::values_type::non_const_type;
544 using range_type = Kokkos::RangePolicy<execution_space, size_t>;
545 using team_policy = Kokkos::TeamPolicy<execution_space>;
546 using member_type =
typename team_policy::member_type;
547 using scratch_view = Kokkos::View<bool*, typename execution_space::scratch_memory_space>;
548 using Ordinal =
typename dev_row_view_t::non_const_value_type;
565 const int max_threads = execution_space::concurrency();
581 Kokkos::PerTeam(
team), [&] () {
590 Kokkos::parallel_for(
614 Kokkos::PerTeam(
team), [&] () {
670#if KOKKOSKERNELS_VERSION >= 40199
671 KokkosKernels::Impl::kk_exclusive_parallel_prefix_sum<
674 KokkosKernels::Impl::kk_exclusive_parallel_prefix_sum<
689 Kokkos::PerTeam(
team), [&] () {
698 Kokkos::parallel_for(
722 Kokkos::PerTeam(
team), [&] () {
775 Kokkos::parallel_for(
"sizing", range_type(0, nrows),
KOKKOS_LAMBDA(
const size_t row) {
784#if KOKKOSKERNELS_VERSION >= 40199
785 KokkosKernels::Impl::kk_exclusive_parallel_prefix_sum<
788 KokkosKernels::Impl::kk_exclusive_parallel_prefix_sum<
794 Kokkos::parallel_for(
"entries", range_type(0, nrows),
KOKKOS_LAMBDA(
const size_t row) {
827 template<
class Scalar,
class LO,
class GO,
class Node>
828 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LO, GO, Node>>
832 using dev_row_view_t =
typename crs_t::local_graph_device_type::row_map_type::non_const_type;
833 using dev_col_view_t =
typename crs_t::local_graph_device_type::entries_type::non_const_type;
834 using dev_val_view_t =
typename crs_t::local_matrix_device_type::values_type::non_const_type;
835 using impl_scalar_t =
typename Kokkos::ArithTraits<Scalar>::val_type;
836 using STS = Kokkos::ArithTraits<impl_scalar_t>;
837 using Ordinal =
typename dev_row_view_t::non_const_value_type;
838 using execution_space =
typename Node::execution_space;
839 using range_type = Kokkos::RangePolicy<execution_space, size_t>;
851 Kokkos::parallel_for(
"sizing", range_type(0, nrows),
KOKKOS_LAMBDA(
const size_t row) {
864#if KOKKOSKERNELS_VERSION >= 40199
865 KokkosKernels::Impl::kk_exclusive_parallel_prefix_sum<
868 KokkosKernels::Impl::kk_exclusive_parallel_prefix_sum<
874 Kokkos::parallel_for(
"entries", range_type(0, nrows),
KOKKOS_LAMBDA(
const size_t row) {
896 template<
class LO,
class GO,
class Node>
897 Teuchos::RCP<const Tpetra::Map<LO,GO,Node> >
900 typedef Teuchos::OrdinalTraits<Tpetra::global_size_t>
TOT;
905 using execution_space =
typename Node::execution_space;
906 using range_type = Kokkos::RangePolicy<execution_space, size_t>;
938 Teuchos::RCP<const map_type>
meshMap = Teuchos::rcp(
new map_type(TOT::invalid(),
meshGids(), 0,
pointMap.getComm()) );
944 template<
class LO,
class GO,
class Node>
945 Teuchos::RCP<const Tpetra::Map<LO,GO,Node> >
948 typedef Teuchos::OrdinalTraits<Tpetra::global_size_t>
TOT;
962 Teuchos::RCP<const map_type>
pointMap = Teuchos::rcp(
new map_type(TOT::invalid(),
pointGids(), 0,
blockMap.getComm()) );
968 template<
class Scalar,
class LO,
class GO,
class Node>
969 Teuchos::RCP<CrsMatrix<Scalar, LO, GO, Node> >
972 using Teuchos::Array;
973 using Teuchos::ArrayView;
980 using crs_graph_type =
typename block_crs_matrix_type::crs_graph_type;
981 using local_graph_device_type =
typename crs_matrix_type::local_graph_device_type;
982 using local_matrix_device_type =
typename crs_matrix_type::local_matrix_device_type;
983 using row_map_type =
typename local_graph_device_type::row_map_type::non_const_type;
984 using entries_type =
typename local_graph_device_type::entries_type::non_const_type;
985 using values_type =
typename local_matrix_device_type::values_type::non_const_type;
990 using little_block_type =
typename block_crs_matrix_type::const_little_block_type;
991 using offset_type =
typename row_map_type::non_const_value_type;
992 using column_type =
typename entries_type::non_const_value_type;
994 using execution_space =
typename Node::execution_space;
995 using range_type = Kokkos::RangePolicy<execution_space, LO>;
999 const offset_type
bs2 = blocksize * blocksize;
1033 for(LO
j=0;
j<blocksize;
j++) {
1084#define TPETRA_BLOCKCRSMATRIX_HELPERS_INSTANT(S,LO,GO,NODE) \
1085 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::string const &fileName); \
1086 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::string const &fileName, Teuchos::ParameterList const ¶ms); \
1087 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::ostream &os); \
1088 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::ostream &os, Teuchos::ParameterList const ¶ms); \
1089 template void writeMatrixStrip(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::ostream &os, Teuchos::ParameterList const ¶ms); \
1090 template Teuchos::RCP<BlockCrsMatrix<S, LO, GO, NODE> > convertToBlockCrsMatrix(const CrsMatrix<S, LO, GO, NODE>& pointMatrix, const LO &blockSize, bool use_LID); \
1091 template Teuchos::RCP<CrsMatrix<S, LO, GO, NODE> > fillLogicalBlocks(const CrsMatrix<S, LO, GO, NODE>& pointMatrix, const LO &blockSize); \
1092 template Teuchos::RCP<CrsMatrix<S, LO, GO, NODE> > unfillFormerBlockCrs(const CrsMatrix<S, LO, GO, NODE>& pointMatrix); \
1093 template Teuchos::RCP<CrsMatrix<S, LO, GO, NODE> > convertToCrsMatrix(const BlockCrsMatrix<S, LO, GO, NODE>& blockMatrix); \
1094 template Teuchos::RCP<CrsGraph<LO, GO, NODE>> getBlockCrsGraph(const Tpetra::CrsMatrix<S, LO, GO, NODE>& pointMatrix, const LO &blockSize, bool use_local_ID);
1099#define TPETRA_CREATEMESHMAP_INSTANT(LO,GO,NODE) \
1100 template Teuchos::RCP<const Map<LO,GO,NODE> > createMeshMap (const LO& blockSize, const Map<LO,GO,NODE>& pointMap, bool use_local_ID); \
1101 template Teuchos::RCP<const Map<LO,GO,NODE> > createPointMap (const LO& blockSize, const Map<LO,GO,NODE>& blockMap);
Struct that holds views of the contents of a CrsMatrix.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::RCP< Tpetra::CrsMatrix< Scalar, LO, GO, Node > > fillLogicalBlocks(const Tpetra::CrsMatrix< Scalar, LO, GO, Node > &pointMatrix, const LO &blockSize)
Fill all point entries in a logical block of a CrsMatrix with zeroes. This should be called before co...
Teuchos::RCP< Tpetra::CrsMatrix< Scalar, LO, GO, Node > > unfillFormerBlockCrs(const Tpetra::CrsMatrix< Scalar, LO, GO, Node > &pointMatrix)
Unfill all point entries in a logical block of a CrsMatrix with zeroes. This can be called after conv...
void writeMatrixStrip(BlockCrsMatrix< Scalar, LO, GO, Node > const &A, std::ostream &os, Teuchos::ParameterList const ¶ms)
Helper function called by blockCrsMatrixWriter.
Teuchos::RCP< Tpetra::CrsGraph< LO, GO, Node > > getBlockCrsGraph(const Tpetra::CrsMatrix< Scalar, LO, GO, Node > &pointMatrix, const LO &blockSize, bool use_local_ID=true)
Non-member constructor that creates the CrsGraph of a BlockCrsMatrix from an existing point CrsMatrix...
Teuchos::RCP< const Tpetra::Map< LO, GO, Node > > createPointMap(LO const &blockSize, const Tpetra::Map< LO, GO, Node > &blockMap)
Helper function to generate a point map from a block map (with a given block size) GIDs associated wi...
Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > createCrsGraph(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember function to create an empty CrsGraph given a row Map and the max number of entries allowed ...
Teuchos::RCP< CrsMatrix< Scalar, LO, GO, Node > > convertToCrsMatrix(const Tpetra::BlockCrsMatrix< Scalar, LO, GO, Node > &blockMatrix)
Non-member constructor that creates a point CrsMatrix from an existing BlockCrsMatrix.
Teuchos::RCP< const Tpetra::Map< LO, GO, Node > > createMeshMap(LO const &blockSize, const Tpetra::Map< LO, GO, Node > &pointMap, bool use_local_ID=false)
Helper function to generate a mesh map from a point map. Important! It's assumed that point GIDs asso...
void blockCrsMatrixWriter(BlockCrsMatrix< Scalar, LO, GO, Node > const &A, std::string const &fileName)
Helper function to write a BlockCrsMatrix. Calls the 3-argument version.
@ INSERT
Insert new values that don't currently exist.
Teuchos::RCP< BlockCrsMatrix< Scalar, LO, GO, Node > > convertToBlockCrsMatrix(const Tpetra::CrsMatrix< Scalar, LO, GO, Node > &pointMatrix, const LO &blockSize, bool use_local_ID=true)
Non-member constructor that creates a BlockCrsMatrix from an existing point CrsMatrix.