Tpetra parallel linear algebra  Version of the Day
Tpetra_Experimental_BlockCrsMatrix_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_EXPERIMENTAL_BLOCKCRSMATRIX_DECL_HPP
43 #define TPETRA_EXPERIMENTAL_BLOCKCRSMATRIX_DECL_HPP
44 
47 
48 #include <ctime>
49 #include <Tpetra_ConfigDefs.hpp>
50 #include <Tpetra_CrsGraph.hpp>
51 #include <Tpetra_RowMatrix.hpp>
52 #include <Tpetra_Experimental_BlockMultiVector.hpp>
53 
54 namespace Tpetra {
55 namespace Experimental {
56 
124 template<class Scalar = Details::DefaultTypes::scalar_type,
126  class GO = Details::DefaultTypes::global_ordinal_type,
129  virtual public Tpetra::RowMatrix<Scalar, LO, GO, Node>,
130  virtual public Tpetra::DistObject<char, LO, GO, Node>
131 {
132 private:
135  typedef Teuchos::ScalarTraits<Scalar> STS;
136 
137 protected:
138  typedef char packet_type;
139 
140 public:
142 
143 
145  typedef Scalar scalar_type;
146 
154 
156  typedef LO local_ordinal_type;
160  typedef Node node_type;
161 
162  typedef ::Tpetra::Map<LO, GO, node_type> map_type;
165 
170 
172 
174 
176  BlockCrsMatrix ();
177 
187  BlockCrsMatrix (const crs_graph_type& graph, const LO blockSize);
188 
196  BlockCrsMatrix (const crs_graph_type& graph,
197  const map_type& domainPointMap,
198  const map_type& rangePointMap,
199  const LO blockSize);
200 
202  virtual ~BlockCrsMatrix () {}
203 
205 
207 
209  Teuchos::RCP<const map_type> getDomainMap () const;
210 
212  Teuchos::RCP<const map_type> getRangeMap () const;
213 
215  Teuchos::RCP<const map_type> getRowMap () const;
216 
218  Teuchos::RCP<const map_type> getColMap () const;
219 
222 
224  size_t getNodeNumRows() const;
225 
226  size_t getNodeMaxNumRowEntries() const;
227 
237  void
238  apply (const mv_type& X,
239  mv_type& Y,
240  Teuchos::ETransp mode = Teuchos::NO_TRANS,
241  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one (),
242  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
243 
246  bool hasTransposeApply () const {
247  // FIXME (mfh 04 May 2014) Transpose and conjugate transpose modes
248  // are not implemented yet. Fill in applyBlockTrans() to fix this.
249  return false;
250  }
251 
253  void setAllToScalar (const Scalar& alpha);
254 
256 
258 
260  std::string description () const;
261 
285  void
286  describe (Teuchos::FancyOStream& out,
287  const Teuchos::EVerbosityLevel verbLevel) const;
288 
290 
292 
294  LO getBlockSize () const { return blockSize_; }
295 
297  virtual Teuchos::RCP<const Tpetra::RowGraph<LO,GO,Node> > getGraph () const;
298 
299  const crs_graph_type & getCrsGraph () const { return graph_; }
300 
305  void
308  Teuchos::ETransp mode = Teuchos::NO_TRANS,
309  const Scalar alpha = Teuchos::ScalarTraits<Scalar>::one (),
310  const Scalar beta = Teuchos::ScalarTraits<Scalar>::zero ());
311 
315  void
319  const Scalar& dampingFactor,
320  const ESweepDirection direction,
321  const int numSweeps,
322  const bool zeroInitialGuess) const;
323 
327  void
331  const ArrayView<LO>& rowIndices,
332  const Scalar& dampingFactor,
333  const ESweepDirection direction,
334  const int numSweeps,
335  const bool zeroInitialGuess) const;
336 
337 
345  void
348  BlockCrsMatrix<Scalar, LO, GO, Node> & factorizedDiagonal,
349  const int * factorizationPivots,
350  const Scalar omega,
351  const ESweepDirection direction) const;
352 
371  LO
372  replaceLocalValues (const LO localRowInd,
373  const LO colInds[],
374  const Scalar vals[],
375  const LO numColInds) const;
376 
395  LO
396  sumIntoLocalValues (const LO localRowInd,
397  const LO colInds[],
398  const Scalar vals[],
399  const LO numColInds) const;
400 
410  LO
411  getLocalRowView (const LO localRowInd,
412  const LO*& colInds,
413  Scalar*& vals,
414  LO& numInds) const;
415 
417  void
418  getLocalRowView (LO LocalRow,
419  Teuchos::ArrayView<const LO> &indices,
420  Teuchos::ArrayView<const Scalar> &values) const;
421 
423  void
424  getLocalRowCopy (LO LocalRow,
425  const Teuchos::ArrayView<LO> &Indices,
426  const Teuchos::ArrayView<Scalar> &Values,
427  size_t &NumEntries) const;
428 
429  little_block_type
430  getLocalBlock (const LO localRowInd, const LO localColInd) const;
431 
455  LO
456  getLocalRowOffsets (const LO localRowInd,
457  ptrdiff_t offsets[],
458  const LO colInds[],
459  const LO numColInds) const;
460 
466  LO
467  replaceLocalValuesByOffsets (const LO localRowInd,
468  const ptrdiff_t offsets[],
469  const Scalar vals[],
470  const LO numOffsets) const;
471 
477  LO
478  sumIntoLocalValuesByOffsets (const LO localRowInd,
479  const ptrdiff_t offsets[],
480  const Scalar vals[],
481  const LO numOffsets) const;
482 
489  size_t getNumEntriesInLocalRow (const LO localRowInd) const;
490 
507  bool localError () const {
508  return *localError_;
509  }
510 
525  std::string errorMessages () const {
526  return (*errs_).is_null () ? std::string ("") : (*errs_)->str ();
527  }
528 
560  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
561 
571  void
573  const Teuchos::ArrayView<const size_t>& offsets) const;
574 
575 
577  void computeDiagonalGraph ();
578 
580  bool isComputedDiagonalGraph() const { return computedDiagonalGraph_;}
581 
582  Teuchos::RCP<crs_graph_type> getDiagonalGraph () const;
583 
584 protected:
586  LO
587  absMaxLocalValues (const LO localRowInd,
588  const LO colInds[],
589  const Scalar vals[],
590  const LO numColInds) const;
591 
593  LO
594  absMaxLocalValuesByOffsets (const LO localRowInd,
595  const ptrdiff_t offsets[],
596  const Scalar vals[],
597  const LO numOffsets) const;
598 
605 
606 
607  virtual bool checkSizes (const Tpetra::SrcDistObject& source);
608 
609  virtual void
610  copyAndPermute (const Tpetra::SrcDistObject& source,
611  size_t numSameIDs,
612  const Teuchos::ArrayView<const LO>& permuteToLIDs,
613  const Teuchos::ArrayView<const LO>& permuteFromLIDs);
614 
615  virtual void
616  packAndPrepare (const Tpetra::SrcDistObject& source,
617  const Teuchos::ArrayView<const LO>& exportLIDs,
618  Teuchos::Array<packet_type>& exports,
619  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
620  size_t& constantNumPackets,
621  Tpetra::Distributor& distor);
622 
623  virtual void
624  unpackAndCombine (const Teuchos::ArrayView<const LO> &importLIDs,
625  const Teuchos::ArrayView<const packet_type> &imports,
626  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
627  size_t constantNumPackets,
628  Tpetra::Distributor& distor,
631 
632 private:
634  crs_graph_type graph_;
635  Teuchos::RCP<crs_graph_type> graphRCP_;
644  map_type rowMeshMap_;
651  map_type domainPointMap_;
658  map_type rangePointMap_;
660  LO blockSize_;
661 
666  typename crs_graph_type::local_graph_type::row_map_type::HostMirror ptr_;
667 
669  const LO* ind_;
675  Teuchos::ArrayRCP<impl_scalar_type> valView_;
680  impl_scalar_type* val_;
681 
703  Teuchos::RCP<Teuchos::RCP<BMV> > X_colMap_;
707  Teuchos::RCP<Teuchos::RCP<BMV> > Y_rowMap_;
708 
716  LO columnPadding_;
717 
719  bool rowMajor_;
720 
732  Teuchos::RCP<bool> localError_;
733 
741  Teuchos::RCP<Teuchos::RCP<std::ostringstream> > errs_;
742 
744  std::ostream& markLocalErrorAndGetStream ();
745 
746  // //! Clear the local error state and stream.
747  // void clearLocalErrorStateAndStream ();
748 
758  void
759  applyBlockTrans (const BlockMultiVector<Scalar, LO, GO, Node>& X,
761  const Teuchos::ETransp mode,
762  const Scalar alpha,
763  const Scalar beta);
764 
772  void
773  applyBlockNoTrans (const BlockMultiVector<Scalar, LO, GO, Node>& X,
775  const Scalar alpha,
776  const Scalar beta);
777 
785  void
786  localApplyBlockNoTrans (const BlockMultiVector<Scalar, LO, GO, Node>& X,
788  const Scalar alpha,
789  const Scalar beta);
790 
791  Teuchos::RCP<crs_graph_type> diagonalGraph_;
792  bool computedDiagonalGraph_;
793 
826  size_t
827  findRelOffsetOfColumnIndex (const LO localRowIndex,
828  const LO colIndexToFind,
829  const size_t hint) const;
830 
833  LO offsetPerBlock () const;
834 
835  const_little_block_type
836  getConstLocalBlockFromInput (const impl_scalar_type* val, const size_t pointOffset) const;
837 
838  little_block_type
839  getNonConstLocalBlockFromInput (impl_scalar_type* val, const size_t pointOffset) const;
840 
841  const_little_block_type
842  getConstLocalBlockFromAbsOffset (const size_t absBlockOffset) const;
843 
844  little_block_type
845  getNonConstLocalBlockFromAbsOffset (const size_t absBlockOffset) const;
846 
847 public:
849  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
850 
852  virtual Teuchos::RCP<Node> getNode() const;
853 
855  virtual global_size_t getGlobalNumCols() const;
856 
857  virtual size_t getNodeNumCols() const;
858 
859  virtual GO getIndexBase() const;
860 
862  virtual global_size_t getGlobalNumEntries() const;
863 
865  virtual size_t getNodeNumEntries() const;
866 
876  virtual size_t getNumEntriesInGlobalRow (GO globalRow) const;
877 
879  virtual global_size_t getGlobalNumDiags() const;
880 
882  virtual size_t getNodeNumDiags() const;
883 
885  virtual size_t getGlobalMaxNumRowEntries() const;
886 
888  virtual bool hasColMap() const;
889 
891  virtual bool isLowerTriangular() const;
892 
894  virtual bool isUpperTriangular() const;
895 
905  virtual bool isLocallyIndexed() const;
906 
916  virtual bool isGloballyIndexed() const;
917 
919  virtual bool isFillComplete() const;
920 
922  virtual bool supportsRowViews() const;
923 
925 
927 
948  virtual void
949  getGlobalRowCopy (GO GlobalRow,
950  const Teuchos::ArrayView<GO> &Indices,
951  const Teuchos::ArrayView<Scalar> &Values,
952  size_t& NumEntries) const;
953 
978  virtual void
979  getGlobalRowView (GO GlobalRow,
980  Teuchos::ArrayView<const GO>& indices,
981  Teuchos::ArrayView<const Scalar>& values) const;
982 
994  virtual void getLocalDiagCopy (Vector<Scalar,LO,GO,Node>& diag) const;
995 
997 
999 
1005  virtual void leftScale (const Vector<Scalar, LO, GO, Node>& x);
1006 
1012  virtual void rightScale (const Vector<Scalar, LO, GO, Node>& x);
1013 
1023  getFrobeniusNorm () const;
1025 };
1026 
1027 
1029  template<class Scalar, class LO, class GO, class Node>
1030  void blockCrsMatrixWriter(BlockCrsMatrix<Scalar,LO,GO,Node> const &A, std::string const &fileName) {
1031  Teuchos::ParameterList pl;
1032  std::ofstream out;
1033  out.open(fileName.c_str());
1034  blockCrsMatrixWriter(A, out, pl);
1035  }
1036 
1038  template<class Scalar, class LO, class GO, class Node>
1039  void blockCrsMatrixWriter(BlockCrsMatrix<Scalar,LO,GO,Node> const &A, std::string const &fileName, Teuchos::ParameterList const &params) {
1040  std::ofstream out;
1041  out.open(fileName.c_str());
1042  blockCrsMatrixWriter(A, out, params);
1043  }
1044 
1046  template<class Scalar, class LO, class GO, class Node>
1047  void blockCrsMatrixWriter(BlockCrsMatrix<Scalar,LO,GO,Node> const &A, std::ostream &os) {
1048  Teuchos::ParameterList pl;
1049  blockCrsMatrixWriter(A, os, pl);
1050  }
1051 
1061  template<class Scalar, class LO, class GO, class Node>
1062  void blockCrsMatrixWriter(BlockCrsMatrix<Scalar,LO,GO,Node> const &A, std::ostream &os, Teuchos::ParameterList const &params) {
1063 
1064  using Teuchos::RCP;
1065  using Teuchos::rcp;
1066 
1067  typedef Teuchos::OrdinalTraits<GO> TOT;
1068  typedef BlockCrsMatrix<Scalar, LO, GO, Node> block_crs_matrix_type;
1069  typedef Tpetra::Import<LO, GO, Node> import_type;
1070  typedef Tpetra::Map<LO, GO, Node> map_type;
1071  typedef Tpetra::MultiVector<GO, LO, GO, Node> mv_type;
1072  typedef Tpetra::CrsGraph<LO, GO, Node> crs_graph_type;
1073 
1074  RCP<const map_type> const rowMap = A.getRowMap(); //"mesh" map
1075  RCP<const Teuchos::Comm<int> > comm = rowMap->getComm();
1076  const int myRank = comm->getRank();
1077  const size_t numProcs = comm->getSize();
1078 
1079  // If true, force use of the import strip-mining infrastructure. This is useful for debugging on one process.
1080  bool alwaysUseParallelAlgorithm = false;
1081  if (params.isParameter("always use parallel algorithm"))
1082  alwaysUseParallelAlgorithm = params.get<bool>("always use parallel algorithm");
1083  bool printMatrixMarketHeader = true;
1084  if (params.isParameter("print MatrixMarket header"))
1085  printMatrixMarketHeader = params.get<bool>("print MatrixMarket header");
1086 
1087  if (printMatrixMarketHeader && myRank==0) {
1088  std::time_t now = std::time(NULL);
1089  os << "%%MatrixMarket matrix coordinate real general" << std::endl;
1090  os << "% time stamp: " << ctime(&now);
1091  os << "% written from " << numProcs << " processes" << std::endl;
1092  os << "% point representation of Tpetra::Experimental::BlockCrsMatrix" << std::endl;
1093  size_t numRows = A.getGlobalNumRows();
1094  size_t numCols = A.getGlobalNumCols();
1095  os << "% " << numRows << " block rows, " << numCols << " block columns" << std::endl;
1096  const LO blockSize = A.getBlockSize();
1097  os << "% block size " << blockSize << std::endl;
1098  os << numRows*blockSize << " " << numCols*blockSize << " " << A.getGlobalNumEntries()*blockSize*blockSize << std::endl;
1099  }
1100 
1101  if (numProcs==1 && !alwaysUseParallelAlgorithm) {
1102  writeMatrixStrip(A,os,params);
1103  } else {
1104  size_t numRows = rowMap->getNodeNumElements();
1105 
1106  //Create source map
1107  RCP<const map_type> allMeshGidsMap = rcp(new map_type(TOT::invalid(), numRows, A.getIndexBase(), comm));
1108  //Create and populate vector of mesh GIDs corresponding to this pid's rows.
1109  //This vector will be imported one pid's worth of information at a time to pid 0.
1110  mv_type allMeshGids(allMeshGidsMap,1);
1111  Teuchos::ArrayRCP<GO> allMeshGidsData = allMeshGids.getDataNonConst(0);
1112 
1113  for (size_t i=0; i<numRows; i++)
1114  allMeshGidsData[i] = rowMap->getGlobalElement(i);
1115  allMeshGidsData = Teuchos::null;
1116 
1117  // Now construct a RowMatrix on PE 0 by strip-mining the rows of the input matrix A.
1118  size_t stripSize = allMeshGids.getGlobalLength() / numProcs;
1119  size_t remainder = allMeshGids.getGlobalLength() % numProcs;
1120  size_t curStart = 0;
1121  size_t curStripSize = 0;
1122  Teuchos::Array<GO> importMeshGidList;
1123  for (size_t i=0; i<numProcs; i++) {
1124  if (myRank==0) { // Only PE 0 does this part
1125  curStripSize = stripSize;
1126  if (i<remainder) curStripSize++; // handle leftovers
1127  importMeshGidList.resize(curStripSize); // Set size of vector to max needed
1128  for (size_t j=0; j<curStripSize; j++) importMeshGidList[j] = j + curStart + A.getIndexBase();
1129  curStart += curStripSize;
1130  }
1131  // The following import map should be non-trivial only on PE 0.
1132  TEUCHOS_TEST_FOR_EXCEPTION(myRank>0 && curStripSize!=0,
1133  std::runtime_error, "Tpetra::Experimental::blockCrsMatrixWriter: (pid "
1134  << myRank << ") map size should be zero, but is " << curStripSize);
1135  RCP<map_type> importMeshGidMap = rcp(new map_type(TOT::invalid(), importMeshGidList(), A.getIndexBase(), comm));
1136  import_type gidImporter(allMeshGidsMap, importMeshGidMap);
1137  mv_type importMeshGids(importMeshGidMap, 1);
1138  importMeshGids.doImport(allMeshGids, gidImporter, INSERT);
1139 
1140  // importMeshGids now has a list of GIDs for the current strip of matrix rows.
1141  // Use these values to build another importer that will get rows of the matrix.
1142 
1143  // The following import map will be non-trivial only on PE 0.
1144  Teuchos::ArrayRCP<const GO> importMeshGidsData = importMeshGids.getData(0);
1145  Teuchos::Array<GO> importMeshGidsGO;
1146  importMeshGidsGO.reserve(importMeshGidsData.size());
1147  for (typename Teuchos::ArrayRCP<const GO>::size_type j=0; j<importMeshGidsData.size(); ++j)
1148  importMeshGidsGO.push_back(importMeshGidsData[j]);
1149  RCP<const map_type> importMap = rcp(new map_type(TOT::invalid(), importMeshGidsGO(), rowMap->getIndexBase(), comm) );
1150 
1151  import_type importer(rowMap,importMap );
1152  size_t numEntriesPerRow = A.getCrsGraph().getGlobalMaxNumRowEntries();
1153  RCP<crs_graph_type> graph = createCrsGraph(importMap,numEntriesPerRow);
1154  RCP<const map_type> domainMap = A.getCrsGraph().getDomainMap();
1155  graph->doImport(A.getCrsGraph(), importer, INSERT);
1156  graph->fillComplete(domainMap, importMap);
1157 
1158  block_crs_matrix_type importA(*graph, A.getBlockSize());
1159  importA.doImport(A, importer, INSERT);
1160 
1161  // Finally we are ready to write this strip of the matrix
1162  writeMatrixStrip(importA, os, params);
1163  }
1164  }
1165  }
1166 
1171  template<class Scalar, class LO, class GO, class Node>
1172  void writeMatrixStrip(BlockCrsMatrix<Scalar,LO,GO,Node> const &A, std::ostream &os, Teuchos::ParameterList const &params) {
1173 
1174  typedef Tpetra::Map<LO, GO, Node> map_type;
1175 
1176  size_t numRows = A.getGlobalNumRows();
1177  RCP<const map_type> rowMap = A.getRowMap();
1178  RCP<const map_type> colMap = A.getColMap();
1179  RCP<const Teuchos::Comm<int> > comm = rowMap->getComm();
1180  const int myRank = comm->getRank();
1181 
1182  const size_t meshRowOffset = rowMap->getIndexBase();
1183  const size_t meshColOffset = colMap->getIndexBase();
1184  TEUCHOS_TEST_FOR_EXCEPTION(meshRowOffset != meshColOffset,
1185  std::runtime_error, "Tpetra::Experimental::writeMatrixStrip: "
1186  "mesh row index base != mesh column index base");
1187 
1188  if (myRank !=0) {
1189 
1190  TEUCHOS_TEST_FOR_EXCEPTION(A.getNodeNumRows() != 0,
1191  std::runtime_error, "Tpetra::Experimental::writeMatrixStrip: pid "
1192  << myRank << " should have 0 rows but has " << A.getNodeNumRows());
1193  TEUCHOS_TEST_FOR_EXCEPTION(A.getNodeNumCols() != 0,
1194  std::runtime_error, "Tpetra::Experimental::writeMatrixStrip: pid "
1195  << myRank << " should have 0 columns but has " << A.getNodeNumCols());
1196 
1197  } else {
1198 
1199  TEUCHOS_TEST_FOR_EXCEPTION(numRows != A.getNodeNumRows(),
1200  std::runtime_error, "Tpetra::Experimental::writeMatrixStrip: "
1201  "number of rows on pid 0 does not match global number of rows");
1202 
1203 
1204  int err = 0;
1205  const LO blockSize = A.getBlockSize();
1206  const size_t numLocalRows = A.getNodeNumRows();
1207  bool precisionChanged=false;
1208  int oldPrecision;
1209  if (params.isParameter("precision")) {
1210  oldPrecision = os.precision(params.get<int>("precision"));
1211  precisionChanged=true;
1212  }
1213  int pointOffset = 1;
1214  if (params.isParameter("zero-based indexing")) {
1215  if (params.get<bool>("zero-based indexing") == true)
1216  pointOffset = 0;
1217  }
1218 
1219  size_t localRowInd;
1220  for (localRowInd = 0; localRowInd < numLocalRows; ++localRowInd) {
1221 
1222  // Get a view of the current row.
1223  const LO* localColInds;
1224  Scalar* vals;
1225  LO numEntries;
1226  err = A.getLocalRowView (localRowInd, localColInds, vals, numEntries);
1227  if (err != 0)
1228  break;
1229  GO globalMeshRowID = rowMap->getGlobalElement(localRowInd) - meshRowOffset;
1230 
1231  for (LO k = 0; k < numEntries; ++k) {
1232  GO globalMeshColID = colMap->getGlobalElement(localColInds[k]) - meshColOffset;
1233  Scalar* const curBlock = vals + blockSize * blockSize * k;
1234  // Blocks are stored in row-major format.
1235  for (LO j = 0; j < blockSize; ++j) {
1236  GO globalPointRowID = globalMeshRowID * blockSize + j + pointOffset;
1237  for (LO i = 0; i < blockSize; ++i) {
1238  GO globalPointColID = globalMeshColID * blockSize + i + pointOffset;
1239  const Scalar curVal = curBlock[i + j * blockSize];
1240  os << globalPointRowID << " " << globalPointColID << " " << curVal << std::endl;
1241  }
1242  }
1243  }
1244  }
1245  if (precisionChanged)
1246  os.precision(oldPrecision);
1247  TEUCHOS_TEST_FOR_EXCEPTION(err != 0,
1248  std::runtime_error, "Tpetra::Experimental::writeMatrixStrip: "
1249  "error getting view of local row " << localRowInd);
1250 
1251  }
1252 
1253  }
1254 
1255 } // namespace Experimental
1256 } // namespace Tpetra
1257 
1258 #endif // TPETRA_EXPERIMENTAL_BLOCKCRSMATRIX_DECL_HPP
LO absMaxLocalValuesByOffsets(const LO localRowInd, const ptrdiff_t offsets[], const Scalar vals[], const LO numOffsets) const
Like sumIntoLocalValuesByOffsets, but for the ABSMAX combine mode.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
virtual bool supportsRowViews() const
Whether this object implements getLocalRowView() and getGlobalRowView().
virtual void copyAndPermute(const Tpetra::SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LO > &permuteToLIDs, const Teuchos::ArrayView< const LO > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
virtual bool isLowerTriangular() const
Whether this matrix is lower triangular.
Teuchos::RCP< const map_type > getColMap() const
get the (mesh) map for the columns of this block matrix.
LO getBlockSize() const
The number of degrees of freedom per mesh point.
Teuchos::RCP< const map_type > getRowMap() const
get the (mesh) map for the rows of this block matrix.
LO replaceLocalValues(const LO localRowInd, const LO colInds[], const Scalar vals[], const LO numColInds) const
Replace values at the given column indices, in the given row.
Scalar scalar_type
The type of entries in the matrix.
LO replaceLocalValuesByOffsets(const LO localRowInd, const ptrdiff_t offsets[], const Scalar vals[], const LO numOffsets) const
Like replaceLocalValues, but avoids computing row offsets.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
void writeMatrixStrip(BlockCrsMatrix< Scalar, LO, GO, Node > const &A, std::ostream &os, Teuchos::ParameterList const &params)
Helper function called by blockCrsMatrixWriter.
size_t getGlobalMaxNumRowEntries() const
Maximum number of entries in all rows over all processes.
size_t getNodeNumRows() const
get the local number of block rows
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
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.
One or more distributed dense vectors.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Print a description of this object to the given output stream.
MultiVector for multiple degrees of freedom per mesh point.
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.
global_size_t getGlobalNumRows() const
get the global number of block rows
Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node, classic > > createCrsGraph(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember function to create an empty CrsGraph given a row Map and the max number of entries allowed ...
Nonowning view of a square dense block in a block matrix.
void blockCrsMatrixWriter(BlockCrsMatrix< Scalar, LO, GO, Node > const &A, std::string const &fileName)
Helper function to write a BlockCrsMatrix. Calls the 3-argument version.
LO absMaxLocalValues(const LO localRowInd, const LO colInds[], const Scalar vals[], const LO numColInds) const
Like sumIntoLocalValues, but for the ABSMAX combine mode.
Teuchos::RCP< const map_type > getRangeMap() const
Get the (point) range Map of this matrix.
virtual bool isUpperTriangular() const
Whether this matrix is upper triangular.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
virtual bool checkSizes(const Tpetra::SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
virtual bool hasColMap() const
Whether this matrix has a well-defined column map.
Teuchos::RCP< const map_type > getDomainMap() const
Get the (point) domain Map of this matrix.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
virtual size_t getNodeNumDiags() const
The number of local diagonal entries, based on global row/column index comparisons.
virtual GO getIndexBase() const
The index base for global indices in this matrix.
virtual bool isGloballyIndexed() const
Whether matrix indices are globally indexed.
size_t global_size_t
Global size_t object.
Insert new values that don&#39;t currently exist.
std::string description() const
One-line description of this object.
BlockCrsMatrix()
Default constructor: Makes an empty block matrix.
Teuchos::RCP< const map_type > getDomainMap() const
Returns the Map associated with the domain of this graph.
virtual global_size_t getGlobalNumCols() const
The global number of columns of this matrix.
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
virtual bool isFillComplete() const
Whether fillComplete() has been called.
Nonowning view of a set of degrees of freedom corresponding to a mesh point in a block vector or mult...
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
void reorderedGaussSeidelCopy(MultiVector< Scalar, LO, GO, Node > &X, const MultiVector< Scalar, LO, GO, Node > &B, const MultiVector< Scalar, LO, GO, Node > &D, const ArrayView< LO > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of reorderedGaussSeidel(), with fewer requirements on X.
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::mag_type mag_type
Type of a norm result.
virtual size_t getNodeNumCols() const
The number of columns needed to apply the forward operator on this node.
virtual size_t getNodeNumEntries() const
The local number of stored (structurally nonzero) entries.
virtual void leftScale(const Vector< Scalar, LO, GO, Node > &x)
Scale the RowMatrix on the left with the given Vector x.
void getLocalDiagCopy(BlockCrsMatrix< Scalar, LO, GO, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
Variant of getLocalDiagCopy() that uses precomputed offsets.
virtual global_size_t getGlobalNumEntries() const
The global number of stored (structurally nonzero) entries.
virtual void getGlobalRowCopy(GO GlobalRow, const Teuchos::ArrayView< GO > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Get a copy of the given global row&#39;s entries.
void localGaussSeidel(const BlockMultiVector< Scalar, LO, GO, Node > &Residual, BlockMultiVector< Scalar, LO, GO, Node > &Solution, BlockCrsMatrix< Scalar, LO, GO, Node > &factorizedDiagonal, const int *factorizationPivots, const Scalar omega, const ESweepDirection direction) const
Local Gauss-Seidel solve given a factorized diagonal.
void getLocalRowCopy(LO LocalRow, const Teuchos::ArrayView< LO > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Not implemented.
Abstract base class for objects that can be the source of an Import or Export operation.
double scalar_type
Default value of Scalar template parameter.
LO getLocalRowView(const LO localRowInd, const LO *&colInds, Scalar *&vals, LO &numInds) const
Get a view of the row, using local indices.
void gaussSeidelCopy(MultiVector< Scalar, LO, GO, Node > &X, const MultiVector< Scalar, LO, GO, Node > &B, const MultiVector< Scalar, LO, GO, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
std::string errorMessages() const
The current stream of error messages.
LO sumIntoLocalValues(const LO localRowInd, const LO colInds[], const Scalar vals[], const LO numColInds) const
Sum into values at the given column indices, in the given row.
bool isComputedDiagonalGraph() const
Reports on whether the DiagonalGraph has been Computed.
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries across all rows/columns on all nodes.
virtual void rightScale(const Vector< Scalar, LO, GO, Node > &x)
Scale the RowMatrix on the right with the given Vector x.
virtual Tpetra::RowMatrix< Scalar, LO, GO, Node >::mag_type getFrobeniusNorm() const
The Frobenius norm of the matrix.
A read-only, row-oriented interface to a sparse matrix.
LO sumIntoLocalValuesByOffsets(const LO localRowInd, const ptrdiff_t offsets[], const Scalar vals[], const LO numOffsets) const
Like sumIntoLocalValues, but avoids computing row offsets.
A distributed dense vector.
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
For this matrix A, compute Y := beta * Y + alpha * Op(A) * X.
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which this matrix is distributed.
virtual global_size_t getGlobalNumDiags() const
The number of global diagonal entries, based on global row/column index comparisons.
bool localError() const
Whether this object had an error on the calling process.
BlockMultiVector< Scalar, LO, GO, Node >::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
virtual Teuchos::RCP< Node > getNode() const
The Kokkos Node instance.
virtual ~BlockCrsMatrix()
Destructor (declared virtual for memory safety).
Base class for distributed Tpetra objects that support data redistribution.
size_t getNodeMaxNumRowEntries() const
The maximum number of entries across all rows/columns on this node.
bool hasTransposeApply() const
Whether it is valid to apply the transpose or conjugate transpose of this matrix. ...
virtual size_t getNumEntriesInGlobalRow(GO globalRow) const
The current number of entries on the calling process in the specified global row. ...
virtual Teuchos::RCP< const Tpetra::RowGraph< LO, GO, Node > > getGraph() const
Get the (mesh) graph.
size_t getNumEntriesInLocalRow(const LO localRowInd) const
Return the number of entries in the given row on the calling process.
virtual void getGlobalRowView(GO GlobalRow, Teuchos::ArrayView< const GO > &indices, Teuchos::ArrayView< const Scalar > &values) const
Get a constant, nonpersisting, globally indexed view of the given row of the matrix.
virtual bool isLocallyIndexed() const
Whether matrix indices are locally indexed.