46 #include <Teuchos_Array.hpp> 52 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy,
toEpetra(rowMap), maxNumEntriesPerRow,
toEpetra(pftype)))), isFillResumed_(false) { }
54 EpetraCrsMatrix::EpetraCrsMatrix(
const RCP<
const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc,
ProfileType pftype,
const Teuchos::RCP< Teuchos::ParameterList > &plist)
55 : isFillResumed_(false)
57 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end());
58 mtx_ = Teuchos::rcp(
new Epetra_CrsMatrix(Copy,
toEpetra(rowMap), numEntriesPerRowToAlloc.getRawPtr(),
toEpetra(pftype)));
61 EpetraCrsMatrix::EpetraCrsMatrix(
const RCP<
const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
const RCP<
const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap,
size_t maxNumEntriesPerRow,
ProfileType pftype,
const Teuchos::RCP< Teuchos::ParameterList > &plist)
62 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy,
toEpetra(rowMap),
toEpetra(colMap), maxNumEntriesPerRow,
toEpetra(pftype)))), isFillResumed_(false) { }
64 EpetraCrsMatrix::EpetraCrsMatrix(
const RCP<
const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
const RCP<
const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap,
const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc,
ProfileType pftype,
const Teuchos::RCP< Teuchos::ParameterList > &plist)
65 : isFillResumed_(false)
67 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end());
68 mtx_ = Teuchos::rcp(
new Epetra_CrsMatrix(Copy,
toEpetra(rowMap),
toEpetra(colMap), numEntriesPerRowToAlloc.getRawPtr(),
toEpetra(pftype)));
72 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy,
toEpetra(graph)))), isFillResumed_(false) { }
74 #ifdef HAVE_XPETRA_EXPERIMENTAL 84 const Teuchos::RCP<Teuchos::ParameterList>& params):
87 XPETRA_DYNAMIC_CAST(
const EpetraCrsMatrix, *sourceMatrix, tSourceMatrix,
"Xpetra::EpetraCrsMatrix constructor only accepts Xpetra::EpetraCrsMatrix as an input argument.");
88 XPETRA_DYNAMIC_CAST(
const EpetraImport, importer, tImporter,
"Xpetra::EpetraCrsMatrix constructor only accepts Xpetra::EpetraImport as an input argument.");
90 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &
toEpetra(domainMap): 0;
91 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &
toEpetra(rangeMap) : 0;
94 bool restrictComm=
false;
95 if(!params.is_null()) restrictComm = params->get(
"Restrict Communicator",restrictComm);
96 mtx_ = Teuchos::rcp(
new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
97 if(restrictComm && mtx_->NumMyRows()==0)
105 const Teuchos::RCP<Teuchos::ParameterList>& params):
108 XPETRA_DYNAMIC_CAST(
const EpetraCrsMatrix, *sourceMatrix, tSourceMatrix,
"Xpetra::EpetraCrsMatrix constructor only accepts Xpetra::EpetraCrsMatrix as an input argument.");
109 XPETRA_DYNAMIC_CAST(
const EpetraExport, exporter, tExporter,
"Xpetra::EpetraCrsMatrix constructor only accepts Xpetra::EpetraExport as an input argument.");
111 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &
toEpetra(domainMap): 0;
112 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &
toEpetra(rangeMap) : 0;
115 bool restrictComm=
false;
116 if(!params.is_null()) restrictComm = params->get(
"Restrict Communicator",restrictComm);
118 mtx_ = Teuchos::rcp(
new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
125 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
130 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
137 const std::string tfecfFuncName(
"replaceGlobalValues");
138 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!
isFillActive(), std::runtime_error,
139 ": Fill must be active in order to call this method. If you have already " 140 "called fillComplete(), you need to call resumeFill() before you can " 143 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
144 std::runtime_error,
": values.size() must equal indices.size().");
147 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
155 const std::string tfecfFuncName(
"replaceGlobalValues");
156 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!
isFillActive(), std::runtime_error,
157 ": Fill must be active in order to call this method. If you have already " 158 "called fillComplete(), you need to call resumeFill() before you can " 161 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
162 std::runtime_error,
": values.size() must equal indices.size().");
165 XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
175 Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
176 double *& myValues = mtx_->ExpertExtractValues();
179 myColind.Resize(numNonZeros);
180 delete [] myValues; myValues =
new double[numNonZeros];
184 colind = Teuchos::arcp(myColind.Values(),0,numNonZeros,
false);
185 values = Teuchos::arcp(myValues,0,numNonZeros,
false);
193 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr()!=mtx_->ExpertExtractIndices().Values(),
Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
194 TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr()!=mtx_->ExpertExtractValues(),
Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
195 TEUCHOS_TEST_FOR_EXCEPTION(values.size()!=colind.size(),
Xpetra::Exceptions::RuntimeError,
"An exception is thrown to let you know that you mismatched your pointers.");
198 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
201 myRowptr.Resize(N+1);
202 for(
size_t i=0; i<N+1; i++)
203 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
225 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
226 NumEntries = numEntries;
236 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
237 if (numEntries == 0) { eValues = NULL; eIndices = NULL; }
239 indices = ArrayView<const int>(eIndices, numEntries);
240 values = ArrayView<const double>(eValues, numEntries);
250 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
251 if (numEntries == 0) { eValues = NULL; eIndices = NULL; }
253 indices = ArrayView<const int>(eIndices, numEntries);
254 values = ArrayView<const double>(eValues, numEntries);
265 TEUCHOS_TEST_FOR_EXCEPTION((mode != Teuchos::NO_TRANS) && (mode != Teuchos::TRANS),
Xpetra::Exceptions::NotImplemented,
"Xpetra::EpetraCrsMatrix->apply() only accept mode == NO_TRANS or mode == TRANS");
269 TEUCHOS_TEST_FOR_EXCEPTION(mtx_->UseTranspose(),
Xpetra::Exceptions::NotImplemented,
"An exception is throw to let you know that Xpetra::EpetraCrsMatrix->apply() do not take into account the UseTranspose() parameter of Epetra_CrsMatrix.");
271 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
274 RCP<Epetra_MultiVector> tmp = Teuchos::rcp(
new Epetra_MultiVector(*epY));
276 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
286 std::ostringstream oss;
289 oss <<
"{status = fill complete" 296 oss <<
"{status = fill not complete" 310 using Teuchos::VERB_DEFAULT;
311 using Teuchos::VERB_NONE;
312 using Teuchos::VERB_LOW;
313 using Teuchos::VERB_MEDIUM;
314 using Teuchos::VERB_HIGH;
315 using Teuchos::VERB_EXTREME;
316 Teuchos::EVerbosityLevel vl = verbLevel;
317 if (vl == VERB_DEFAULT) vl = VERB_LOW;
318 RCP<const Comm<int> > comm = this->
getComm();
319 const int myImageID = comm->getRank(),
320 numImages = comm->getSize();
325 width = std::max<size_t>(width,11) + 2;
326 Teuchos::OSTab tab(out);
334 if (vl != VERB_NONE) {
335 if (myImageID == 0) out << this->
description() << std::endl;
342 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
343 if (myImageID == 0) out <<
"\nRow map: " << std::endl;
348 if (myImageID == 0) out <<
"\nColumn map is row map.";
351 if (myImageID == 0) out <<
"\nColumn map: " << std::endl;
357 if (myImageID == 0) out <<
"\nDomain map is row map.";
360 if (myImageID == 0) out <<
"\nDomain map is row map.";
363 if (myImageID == 0) out <<
"\nDomain map: " << std::endl;
369 if (myImageID == 0) out <<
"\nRange map is domain map." << std::endl;
372 if (myImageID == 0) out <<
"\nRange map is row map." << std::endl;
375 if (myImageID == 0) out <<
"\nRange map: " << std::endl;
379 if (myImageID == 0) out << std::endl;
382 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
383 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
384 if (myImageID == imageCtr) {
385 out <<
"Node ID = " << imageCtr << std::endl;
400 out <<
"Node number of diagonals = " <<
getNodeNumDiags() << std::endl;
410 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
411 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
412 if (myImageID == imageCtr) {
413 out << std::setw(width) <<
"Node ID" 414 << std::setw(width) <<
"Global Row" 415 << std::setw(width) <<
"Num Entries";
416 if (vl == VERB_EXTREME) {
417 out << std::setw(width) <<
"(Index,Value)";
423 out << std::setw(width) << myImageID
424 << std::setw(width) << gid
425 << std::setw(width) << nE;
426 if (vl == VERB_EXTREME) {
428 ArrayView<const GlobalOrdinal> rowinds;
429 ArrayView<const Scalar> rowvals;
431 for (
size_t j=0; j < nE; ++j) {
432 out <<
" (" << rowinds[j]
433 <<
", " << rowvals[j]
438 ArrayView<const LocalOrdinal> rowinds;
439 ArrayView<const Scalar> rowvals;
441 for (
size_t j=0; j < nE; ++j) {
442 out <<
" (" <<
getColMap()->getGlobalElement(rowinds[j])
443 <<
", " << rowvals[j]
466 XPETRA_DYNAMIC_CAST(
const EpetraImport, importer, tImporter,
"Xpetra::EpetraCrsMatrix::doImport only accept Xpetra::EpetraImport as input arguments.");
468 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
469 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(),
toEpetra(CM));
470 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
"Catch error code returned by Epetra.");
478 XPETRA_DYNAMIC_CAST(
const EpetraImport, importer, tImporter,
"Xpetra::EpetraCrsMatrix::doImport only accept Xpetra::EpetraImport as input arguments.");
480 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
481 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(),
toEpetra(CM));
482 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
"Catch error code returned by Epetra.");
490 XPETRA_DYNAMIC_CAST(
const EpetraExport, exporter, tExporter,
"Xpetra::EpetraCrsMatrix::doImport only accept Xpetra::EpetraImport as input arguments.");
492 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
493 int err = mtx_->Import(*v, *tExporter.getEpetra_Export(),
toEpetra(CM));
494 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
"Catch error code returned by Epetra.");
503 XPETRA_DYNAMIC_CAST(
const EpetraExport, exporter, tExporter,
"Xpetra::EpetraCrsMatrix::doImport only accept Xpetra::EpetraImport as input arguments.");
505 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
506 int err = mtx_->Export(*v, *tExporter.getEpetra_Export(),
toEpetra(CM));
507 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
"Catch error code returned by Epetra.");
512 const RCP< ParameterList > ¶ms) {
518 bool doOptimizeStorage =
true;
519 if (params != null && params->get(
"Optimize Storage",
true) ==
false) doOptimizeStorage =
false;
520 mtx_->FillComplete(
toEpetra(domainMap),
toEpetra(rangeMap), doOptimizeStorage);
529 bool doOptimizeStorage =
true;
530 if (params != null && params->get(
"Optimize Storage",
true) ==
false) doOptimizeStorage =
false;
531 mtx_->FillComplete(doOptimizeStorage);
537 XPETRA_DYNAMIC_CAST(
const EpetraImport, *newImporter, eImporter,
"Xpetra::EpetraCrsMatrix::replaceDomainMapAndImporter only accepts Xpetra::EpetraImport.");
539 const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
541 if(myImport==Teuchos::null)
542 rv=mtx_->ReplaceDomainMapAndImporter(
toEpetra(newDomainMap),0);
544 rv=mtx_->ReplaceDomainMapAndImporter(
toEpetra(newDomainMap),&*myImport);
545 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error,
"Xpetra::EpetraCrsMatrix::replaceDomainMapAndImporter FAILED!");
553 const RCP<ParameterList> & params) {
556 const Epetra_Import * myimport =0;
557 const Epetra_Export * myexport =0;
559 if(!importer.is_null()) {
561 myimport = eImporter.getEpetra_Import().getRawPtr();
563 if(!exporter.is_null()) {
565 myexport = eExporter.getEpetra_Export().getRawPtr();
568 rv=mtx_->ExpertStaticFillComplete(
toEpetra(domainMap),
toEpetra(rangeMap), myimport, myexport);
570 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error,
"Xpetra::EpetraCrsMatrix::expertStaticFillComplete FAILED!");
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
void resumeFill(const RCP< ParameterList > ¶ms=null)
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
EpetraCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Constructor specifying fixed number of entries for each row.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
Exception throws to report errors in the internal logical of the program.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the matrix's structure from the Crs arrays.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, int > > &graph)
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
#define XPETRA_ERR_CHECK(arg)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
Exception throws when you call an unimplemented method of Xpetra.
bool isFillActive() const
Returns true if the matrix is in edit mode.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > ¶ms=Teuchos::null)
Expert static fill complete.
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
CombineMode
Xpetra::Combine Mode enumerable type.
#define XPETRA_MONITOR(funcName)
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms=null)
Signal that data entry is complete, specifying domain and range maps.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
RCP< Epetra_CrsMatrix > mtx_
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
std::string description() const
A simple one-line description of this object.