40#ifndef TPETRA_BLOCKCRSMATRIX_HELPERS_DEF_HPP
41#define TPETRA_BLOCKCRSMATRIX_HELPERS_DEF_HPP
45#include "Tpetra_BlockCrsMatrix.hpp"
46#include "Tpetra_CrsMatrix.hpp"
47#include "Tpetra_HashTable.hpp"
48#include "Tpetra_Import.hpp"
49#include "Tpetra_Map.hpp"
50#include "Tpetra_MultiVector.hpp"
51#include "Teuchos_ParameterList.hpp"
52#include "Teuchos_ScalarTraits.hpp"
58 template<
class Scalar,
class LO,
class GO,
class Node>
60 Teuchos::ParameterList
pl;
66 template<
class Scalar,
class LO,
class GO,
class Node>
73 template<
class Scalar,
class LO,
class GO,
class Node>
75 Teuchos::ParameterList
pl;
79 template<
class Scalar,
class LO,
class GO,
class Node>
85 typedef Teuchos::OrdinalTraits<GO>
TOT;
94 const int myRank = comm->getRank();
95 const size_t numProcs = comm->getSize();
99 if (
params.isParameter(
"always use parallel algorithm"))
102 if (
params.isParameter(
"print MatrixMarket header"))
106 std::time_t
now = std::time(
NULL);
109 Teuchos::ScalarTraits<Scalar>::isComplex ?
"complex" :
"real";
119 os <<
"%%MatrixMarket matrix coordinate " <<
dataTypeStr <<
" general" << std::endl;
121 os <<
"% written from " <<
numProcs <<
" processes" << std::endl;
122 os <<
"% point representation of Tpetra::BlockCrsMatrix" << std::endl;
123 size_t numRows =
A.getGlobalNumRows();
124 size_t numCols =
A.getGlobalNumCols();
125 os <<
"% " <<
numRows <<
" block rows, " << numCols <<
" block columns" << std::endl;
134 size_t numRows = rowMap->getLocalNumElements();
163 std::runtime_error,
"Tpetra::blockCrsMatrixWriter: (pid "
197 template<
class Scalar,
class LO,
class GO,
class Node>
204 using impl_scalar_type =
typename bcrs_type::impl_scalar_type;
206 size_t numRows =
A.getGlobalNumRows();
210 const int myRank = comm->getRank();
215 std::runtime_error,
"Tpetra::writeMatrixStrip: "
216 "mesh row index base != mesh column index base");
221 std::runtime_error,
"Tpetra::writeMatrixStrip: pid "
222 <<
myRank <<
" should have 0 rows but has " <<
A.getLocalNumRows());
224 std::runtime_error,
"Tpetra::writeMatrixStrip: pid "
225 <<
myRank <<
" should have 0 columns but has " <<
A.getLocalNumCols());
230 std::runtime_error,
"Tpetra::writeMatrixStrip: "
231 "number of rows on pid 0 does not match global number of rows");
239 if (
params.isParameter(
"precision")) {
244 if (
params.isParameter(
"zero-based indexing")) {
245 if (
params.get<
bool>(
"zero-based indexing") ==
true)
259 for (LO
k = 0;
k < numEntries; ++
k) {
270 if (Teuchos::ScalarTraits<impl_scalar_type>::isComplex) {
274 << Teuchos::ScalarTraits<impl_scalar_type>::imag (
curVal);
287 std::runtime_error,
"Tpetra::writeMatrixStrip: "
288 "error getting view of local row " <<
localRowInd);
294 template<
class Scalar,
class LO,
class GO,
class Node>
295 Teuchos::RCP<BlockCrsMatrix<Scalar, LO, GO, Node> >
307 using Teuchos::Array;
308 using Teuchos::ArrayView;
321 if(
meshColMap.is_null())
throw std::runtime_error(
"ERROR: Cannot create mesh colmap");
338 typename crs_matrix_type::local_inds_host_view_type
pointColInds;
339 typename crs_matrix_type::values_host_view_type
pointVals;
354 std::ostringstream
oss;
355 oss<<
"["<<
i<<
"] ERROR: meshColId "<<
meshColInd <<
" is not in the column map. Correspnds to pointColId = "<<
pointColInds[
k]<<std::endl;
356 throw std::runtime_error(
oss.str());
383 std::map<int,int>::iterator
iter;
417 if (std::is_same<typename block_crs_matrix_type::little_block_type::array_layout,Kokkos::LayoutLeft>::value) {
443 template<
class LO,
class GO,
class Node>
444 Teuchos::RCP<const Tpetra::Map<LO,GO,Node> >
447 typedef Teuchos::OrdinalTraits<Tpetra::global_size_t>
TOT;
468 Teuchos::RCP<const map_type>
meshMap = Teuchos::rcp(
new map_type(TOT::invalid(),
meshGids(), 0,
pointMap.getComm()) );
474 template<
class LO,
class GO,
class Node>
475 Teuchos::RCP<const Tpetra::Map<LO,GO,Node> >
478 typedef Teuchos::OrdinalTraits<Tpetra::global_size_t>
TOT;
492 Teuchos::RCP<const map_type>
pointMap = Teuchos::rcp(
new map_type(TOT::invalid(),
pointGids(), 0,
blockMap.getComm()) );
498 template<
class Scalar,
class LO,
class GO,
class Node>
499 Teuchos::RCP<CrsMatrix<Scalar, LO, GO, Node> >
502 using Teuchos::Array;
503 using Teuchos::ArrayView;
510 using crs_graph_type =
typename block_crs_matrix_type::crs_graph_type;
511 using local_graph_device_type =
typename crs_matrix_type::local_graph_device_type;
512 using local_matrix_device_type =
typename crs_matrix_type::local_matrix_device_type;
513 using row_map_type =
typename local_graph_device_type::row_map_type::non_const_type;
514 using entries_type =
typename local_graph_device_type::entries_type::non_const_type;
515 using values_type =
typename local_matrix_device_type::values_type::non_const_type;
520 using little_block_type =
typename block_crs_matrix_type::const_little_block_type;
521 using offset_type =
typename row_map_type::non_const_value_type;
522 using column_type =
typename entries_type::non_const_value_type;
524 using execution_space =
typename Node::execution_space;
525 using range_type = Kokkos::RangePolicy<execution_space, LO>;
529 const offset_type
bs2 = blocksize * blocksize;
563 for(LO
j=0;
j<blocksize;
j++) {
614#define TPETRA_BLOCKCRSMATRIX_HELPERS_INSTANT(S,LO,GO,NODE) \
615 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::string const &fileName); \
616 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::string const &fileName, Teuchos::ParameterList const ¶ms); \
617 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::ostream &os); \
618 template void blockCrsMatrixWriter(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::ostream &os, Teuchos::ParameterList const ¶ms); \
619 template void writeMatrixStrip(BlockCrsMatrix<S,LO,GO,NODE> const &A, std::ostream &os, Teuchos::ParameterList const ¶ms); \
620 template Teuchos::RCP<BlockCrsMatrix<S, LO, GO, NODE> > convertToBlockCrsMatrix(const CrsMatrix<S, LO, GO, NODE>& pointMatrix, const LO &blockSize); \
621 template Teuchos::RCP<CrsMatrix<S, LO, GO, NODE> > convertToCrsMatrix(const BlockCrsMatrix<S, LO, GO, NODE>& blockMatrix);
626#define TPETRA_CREATEMESHMAP_INSTANT(LO,GO,NODE) \
627 template Teuchos::RCP<const Map<LO,GO,NODE> > createMeshMap (const LO& blockSize, const Map<LO,GO,NODE>& pointMap); \
628 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.
void writeMatrixStrip(BlockCrsMatrix< Scalar, LO, GO, Node > const &A, std::ostream &os, Teuchos::ParameterList const ¶ms)
Helper function called by blockCrsMatrixWriter.
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< BlockCrsMatrix< Scalar, LO, GO, Node > > convertToBlockCrsMatrix(const Tpetra::CrsMatrix< Scalar, LO, GO, Node > &pointMatrix, const LO &blockSize)
Non-member constructor that creates a BlockCrsMatrix from an existing point CrsMatrix.
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< const Tpetra::Map< LO, GO, Node > > createMeshMap(LO const &blockSize, const Tpetra::Map< LO, GO, Node > &pointMap)
Helper function to generate a mesh map from a point map. Important! It's assumed that point GIDs asso...