11 #ifndef AMESOS2_EPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
12 #define AMESOS2_EPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
14 #include <Epetra_LocalMap.h>
15 #include <Epetra_Import.h>
19 #include "Amesos2_MatrixAdapter_def.hpp"
24 ConcreteMatrixAdapter<Epetra_CrsMatrix>::ConcreteMatrixAdapter(RCP<Epetra_CrsMatrix> m)
25 : AbstractConcreteMatrixAdapter<Epetra_RowMatrix,Epetra_CrsMatrix>(m)
28 Teuchos::RCP<const MatrixAdapter<Epetra_CrsMatrix> >
29 ConcreteMatrixAdapter<Epetra_CrsMatrix>::get_impl(
const Teuchos::Ptr<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
EDistribution distribution)
const
33 using Teuchos::rcpFromRef;
35 RCP<const Epetra_Map> o_map, t_map;
36 o_map = rcpFromRef(this->mat_->RowMap());
37 t_map = Util::tpetra_map_to_epetra_map<local_ordinal_t,global_ordinal_t,global_size_t,node_t>(*map);
39 const int maxRowNNZ = 0;
40 RCP<Epetra_CrsMatrix> t_mat = rcp(
new Epetra_CrsMatrix(Copy, *t_map, maxRowNNZ));
42 Epetra_Import importer(*t_map, *o_map);
43 t_mat->Import(*(this->mat_), importer, Insert);
44 t_mat->FillComplete();
47 if ( distribution == CONTIGUOUS_AND_ROOTED ) {
49 auto myRank = map->getComm()->getRank();
51 const int global_num_contiguous_entries = t_mat->NumGlobalRows();
52 const int local_num_contiguous_entries = (myRank == 0) ? t_mat->NumGlobalRows() : 0;
54 RCP<const Epetra_Map> contiguousRowMap = rcp(
new Epetra_Map(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->Comm() ) ) );
55 RCP<const Epetra_Map> contiguousColMap = rcp(
new Epetra_Map(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->Comm() ) ) );
56 RCP<const Epetra_Map> contiguousDomainMap = rcp(
new Epetra_Map(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->Comm() ) ) );
57 RCP<const Epetra_Map> contiguousRangeMap = rcp(
new Epetra_Map(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->Comm() ) ) );
59 RCP<Epetra_CrsMatrix> contiguous_t_mat = rcp(
new Epetra_CrsMatrix(Epetra_DataAccess::Copy, *contiguousRowMap, *contiguousColMap, t_mat->MaxNumEntries()) );
66 for (
int row = 0; row < t_mat->NumMyRows(); row++) {
67 t_mat->ExtractMyRowView(row, num_entries, values, indices);
68 contiguous_t_mat->InsertMyValues(row, num_entries, values, indices);
72 contiguous_t_mat->FillComplete(*contiguousDomainMap, *contiguousRangeMap);
74 return rcp (
new ConcreteMatrixAdapter<Epetra_CrsMatrix> (contiguous_t_mat));
77 return( rcp(
new ConcreteMatrixAdapter<Epetra_CrsMatrix>(t_mat)) );
80 Teuchos::RCP<const MatrixAdapter<Epetra_CrsMatrix> >
81 ConcreteMatrixAdapter<Epetra_CrsMatrix>::reindex_impl(Teuchos::RCP<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > &contigRowMap,
82 Teuchos::RCP<
const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > &contigColMap)
const
84 #if defined(HAVE_AMESOS2_EPETRAEXT)
87 using Teuchos::rcpFromRef;
88 auto CrsMatrix =
const_cast<Epetra_CrsMatrix *
>(this->mat_.getRawPtr());
90 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Amesos2_EpetraCrsMatrix_MatrixAdapter requires CsrMatrix to reindex matrices.");
94 RCP<const Epetra_Map> OriginalMap = rcpFromRef(CrsMatrix->RowMap());
95 int NumGlobalElements = OriginalMap->NumGlobalElements();
96 int NumMyElements = OriginalMap->NumMyElements();
97 auto ReindexMap = rcp(
new Epetra_Map( NumGlobalElements, NumMyElements, 0, OriginalMap->Comm() ) );
100 StdIndex_ = rcp(
new EpetraExt::CrsMatrix_Reindex( *ReindexMap ) );
101 ContigMat_ = rcpFromRef((*StdIndex_)( *CrsMatrix ));
103 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Amesos2_EpetraCrsMatrix_MatrixAdapter reindexing failed.");
105 return rcp(
new ConcreteMatrixAdapter<Epetra_CrsMatrix>(ContigMat_));
107 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"ConcreteMatrixAdapter<Epetra_CrsMatrix> requires EpetraExt to reindex matrices.");
113 const Teuchos::EVerbosityLevel verbLevel)
const
115 this->mat_->Print(*(os.getOStream()));
119 #endif // AMESOS2_EPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
void describe(Teuchos::FancyOStream &os, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print a description of this adapter to the given output stream.
Definition: Amesos2_EpetraCrsMatrix_MatrixAdapter_def.hpp:112
Definitions for the Epetra_RowMatrix abstract adapter.
Specialization of the ConcreteMatrixAdapter for Epetra_CrsMatrix. Inherits all its functionality from...
EDistribution
Definition: Amesos2_TypeDecl.hpp:89