51 template<
class EpetraGlobalOrdinal>
55 template<
class EpetraGlobalOrdinal>
63 template<
class EpetraGlobalOrdinal>
67 template<
class EpetraGlobalOrdinal>
75 template<
class EpetraGlobalOrdinal>
79 template<
class EpetraGlobalOrdinal>
84 template<
class EpetraGlobalOrdinal>
95 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &
toEpetra(domainMap): 0;
96 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &
toEpetra(rangeMap) : 0;
99 bool restrictComm=
false;
100 if(!params.
is_null()) restrictComm = params->
get(
"Restrict Communicator",restrictComm);
101 mtx_ =
Teuchos::rcp(
new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
102 if(restrictComm &&
mtx_->NumMyRows()==0)
106 template<
class EpetraGlobalOrdinal>
117 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &
toEpetra(domainMap): 0;
118 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &
toEpetra(rangeMap) : 0;
121 bool restrictComm=
false;
122 if(!params.
is_null()) restrictComm = params->
get(
"Restrict Communicator",restrictComm);
124 mtx_ =
Teuchos::rcp(
new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
127 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR 128 template<
class EpetraGlobalOrdinal>
131 const local_matrix_type& lclMatrix,
134 typedef typename local_matrix_type::size_type size_type;
135 typedef typename local_matrix_type::value_type value_type;
136 typedef typename local_matrix_type::ordinal_type ordinal_type;
139 ordinal_type lclNumRows = lclMatrix.numRows ();
140 ordinal_type lclNumCols = lclMatrix.numCols ();
146 std::vector<GlobalOrdinal> domainMapGids;
149 for (ordinal_type r = 0; r < lclNumRows; ++r) {
151 Kokkos::SparseRowView<local_matrix_type,size_type> rowview = lclMatrix.template row<size_type>(r);
152 NumEntriesPerRowToAlloc[r] = rowview.length;
161 for (ordinal_type r = 0; r < lclNumRows; ++r) {
163 Kokkos::SparseRowView<local_matrix_type,size_type> rowview = lclMatrix.template row<size_type>(r);
169 for(ordinal_type c = 0; c < rowview.length; c++) {
170 value_type value = rowview.value (c);
171 ordinal_type colidx = rowview.colidx (c);
180 if(rowMap->isNodeGlobalElement(gcid)) domainMapGids.push_back(gcid);
187 std::sort(domainMapGids.begin(), domainMapGids.end());
188 domainMapGids.erase(std::unique(domainMapGids.begin(), domainMapGids.end()), domainMapGids.end());
198 template<
class EpetraGlobalOrdinal>
204 template<
class EpetraGlobalOrdinal>
210 template<
class EpetraGlobalOrdinal>
215 const std::string tfecfFuncName(
"replaceGlobalValues");
217 ": Fill must be active in order to call this method. If you have already " 218 "called fillComplete(), you need to call resumeFill() before you can " 222 std::runtime_error,
": values.size() must equal indices.size().");
229 template<
class EpetraGlobalOrdinal>
234 const std::string tfecfFuncName(
"replaceLocalValues");
236 ": Fill must be active in order to call this method. If you have already " 237 "called fillComplete(), you need to call resumeFill() before you can " 241 std::runtime_error,
": values.size() must equal indices.size().");
248 template<
class EpetraGlobalOrdinal>
260 bool ownMemory =
false;
264 Epetra_IntSerialDenseVector& myColind =
mtx_->ExpertExtractIndices();
265 myColind.Resize(numNonZeros);
266 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
270 double *& myValues =
mtx_->ExpertExtractValues();
272 myValues =
new double[numNonZeros];
273 values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
276 template<
class EpetraGlobalOrdinal>
282 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
284 "An exception is thrown to let you know that you mismatched your pointers.");
287 if (values.
size() > 0) {
289 "An exception is thrown to let you know that you mismatched your pointers.");
291 "An exception is thrown to let you know that you mismatched your pointers.");
298 Epetra_IntSerialDenseVector& myRowptr =
mtx_->ExpertExtractIndexOffset();
299 myRowptr.Resize(N+1);
300 for (
size_t i = 0; i < N+1; i++)
301 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
304 template<
class EpetraGlobalOrdinal>
309 bool ownMemory =
false;
316 Epetra_IntSerialDenseVector& myRowptr =
mtx_->ExpertExtractIndexOffset();
318 for (
size_t i = 0; i < n+1; i++)
319 (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
322 colind = Teuchos::arcp(
mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
325 values = Teuchos::arcp(
mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
328 template<
class EpetraGlobalOrdinal>
336 template<
class EpetraGlobalOrdinal>
339 template<
class EpetraGlobalOrdinal>
342 template<
class EpetraGlobalOrdinal>
346 template<
class EpetraGlobalOrdinal>
352 NumEntries = numEntries;
355 template<
class EpetraGlobalOrdinal>
361 NumEntries = numEntries;
364 template<
class EpetraGlobalOrdinal>
373 if (numEntries == 0) { eValues = NULL; eIndices = NULL; }
379 template<
class EpetraGlobalOrdinal>
388 if (numEntries == 0) { eValues = NULL; eIndices = NULL; }
394 template<
class EpetraGlobalOrdinal>
395 void EpetraCrsMatrixT<EpetraGlobalOrdinal>::apply(
const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X,
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y,
Teuchos::ETransp mode,
Scalar alpha,
Scalar beta)
const {
420 template<
class EpetraGlobalOrdinal>
425 std::ostringstream oss;
428 oss <<
"{status = fill complete" 435 oss <<
"{status = fill not complete" 443 template<
class EpetraGlobalOrdinal>
459 const int myImageID = comm->getRank(),
460 numImages = comm->getSize();
465 width = std::max<size_t>(width,11) + 2;
475 if (myImageID == 0) out << this->
description() << std::endl;
483 if (myImageID == 0) out <<
"\nRow map: " << std::endl;
488 if (myImageID == 0) out <<
"\nColumn map is row map.";
491 if (myImageID == 0) out <<
"\nColumn map: " << std::endl;
497 if (myImageID == 0) out <<
"\nDomain map is row map.";
500 if (myImageID == 0) out <<
"\nDomain map is row map.";
503 if (myImageID == 0) out <<
"\nDomain map: " << std::endl;
509 if (myImageID == 0) out <<
"\nRange map is domain map." << std::endl;
512 if (myImageID == 0) out <<
"\nRange map is row map." << std::endl;
515 if (myImageID == 0) out <<
"\nRange map: " << std::endl;
519 if (myImageID == 0) out << std::endl;
523 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
524 if (myImageID == imageCtr) {
525 out <<
"Node ID = " << imageCtr << std::endl;
540 out <<
"Node number of diagonals = " <<
getNodeNumDiags() << std::endl;
551 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
552 if (myImageID == imageCtr) {
553 out << std::setw(width) <<
"Node ID" 554 << std::setw(width) <<
"Global Row" 555 << std::setw(width) <<
"Num Entries";
557 out << std::setw(width) <<
"(Index,Value)";
563 out << std::setw(width) << myImageID
564 << std::setw(width) << gid
565 << std::setw(width) << nE;
571 for (
size_t j=0; j < nE; ++j) {
572 out <<
" (" << rowinds[j]
573 <<
", " << rowvals[j]
581 for (
size_t j=0; j < nE; ++j) {
582 out <<
" (" <<
getColMap()->getGlobalElement(rowinds[j])
583 <<
", " << rowvals[j]
601 template<
class EpetraGlobalOrdinal>
610 int err =
mtx_->Import(*v, *tImporter.getEpetra_Import(),
toEpetra(CM));
614 template<
class EpetraGlobalOrdinal>
623 int err =
mtx_->Export(*v, *tImporter.getEpetra_Import(),
toEpetra(CM));
627 template<
class EpetraGlobalOrdinal>
636 int err =
mtx_->Import(*v, *tExporter.getEpetra_Export(),
toEpetra(CM));
641 template<
class EpetraGlobalOrdinal>
650 int err =
mtx_->Export(*v, *tExporter.getEpetra_Export(),
toEpetra(CM));
654 template<
class EpetraGlobalOrdinal>
663 bool doOptimizeStorage =
true;
664 if (params != null && params->
get(
"Optimize Storage",
true) ==
false) doOptimizeStorage =
false;
668 template<
class EpetraGlobalOrdinal>
675 bool doOptimizeStorage =
true;
676 if (params != null && params->
get(
"Optimize Storage",
true) ==
false) doOptimizeStorage =
false;
677 mtx_->FillComplete(doOptimizeStorage);
681 template<
class EpetraGlobalOrdinal>
688 if(myImport==Teuchos::null)
689 rv=
mtx_->ReplaceDomainMapAndImporter(
toEpetra(newDomainMap),0);
691 rv=
mtx_->ReplaceDomainMapAndImporter(
toEpetra(newDomainMap),&*myImport);
696 template<
class EpetraGlobalOrdinal>
704 const Epetra_Import * myimport =0;
705 const Epetra_Export * myexport =0;
707 if(!importer.is_null()) {
709 myimport = eImporter.getEpetra_Import().getRawPtr();
711 if(!exporter.is_null()) {
713 myexport = eExporter.getEpetra_Export().getRawPtr();
721 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES 725 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
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.
CrsMatrix< double, int, GlobalOrdinal >::scalar_type Scalar
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with Xpetra-defined contiguous uniform distribution.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal > > &graph)
CrsMatrix< double, int, GlobalOrdinal >::local_ordinal_type LocalOrdinal
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
T & get(const std::string &name, T def_value)
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< Epetra_CrsMatrix > mtx_
Exception throws to report errors in the internal logical of the program.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
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.
void resize(const size_type n, const T &val=T())
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
#define XPETRA_ERR_CHECK(arg)
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...
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.
EpetraCrsMatrixT(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.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
std::string description() const
A simple one-line description of this object.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Exception throws when you call an unimplemented method of Xpetra.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
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 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.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
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.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void resumeFill(const RCP< ParameterList > ¶ms=null)
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
CombineMode
Xpetra::Combine Mode enumerable type.
#define XPETRA_MONITOR(funcName)
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.
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 > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
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...
const RCP< const Comm< int > > getComm() const
Returns the communicator.
EpetraGlobalOrdinal GlobalOrdinal
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
ArrayView< T > view(size_type lowerOffset, size_type size) const