44 #include <Epetra_Export.h> 45 #include <Epetra_CrsGraph.h> 46 #include <Epetra_CrsMatrix.h> 47 #include <Epetra_Map.h> 48 #include <Epetra_Import.h> 49 #include <Epetra_Export.h> 51 #include <Teuchos_TimeMonitor.hpp> 61 double *tmp =
new double[nnew];
62 for(
int i=0; i<nold; i++)
73 if( TransposeMatrix_ )
delete TransposeMatrix_;
75 if( !OrigMatrixIsCrsMatrix_ )
83 Epetra_CrsMatrix* EpetraExt::RowMatrix_Transpose::BuildTempTrans()
85 #ifdef ENABLE_TRANSPOSE_TIMINGS 86 Teuchos::Time myTime(
"global");
87 Teuchos::TimeMonitor MM(myTime);
88 Teuchos::RCP<Teuchos::Time> mtime;
89 mtime=MM.getNewTimer(
"Transpose: BuildTempTrans 1");
94 const Epetra_RowMatrix & orig = *
origObj_;
95 const Epetra_CrsMatrix * OrigCrsMatrix =
dynamic_cast<const Epetra_CrsMatrix*
>(&orig);
96 const Epetra_Map & TransMap = orig.RowMatrixColMap();
97 int TransNnz = orig.NumMyNonzeros();
100 Epetra_CrsMatrix *TempTransA1 =
new Epetra_CrsMatrix(Copy, TransMap,orig.RowMatrixRowMap(),0);
101 Epetra_IntSerialDenseVector & TransRowptr = TempTransA1->ExpertExtractIndexOffset();
102 Epetra_IntSerialDenseVector & TransColind = TempTransA1->ExpertExtractIndices();
103 double *& TransVals = TempTransA1->ExpertExtractValues();
105 TransRowptr.Resize(NumMyCols_+1);
106 TransColind.Resize(TransNnz);
108 std::vector<int> CurrentStart(NumMyCols_,0);
111 if (OrigMatrixIsCrsMatrix_)
113 const Epetra_CrsGraph & OrigGraph = OrigCrsMatrix->Graph();
115 for (i=0; i<NumMyRows_; i++)
117 err = OrigGraph.ExtractMyRowView(i, NumIndices, Indices_);
118 if (err != 0)
throw OrigGraph.ReportError(
"ExtractMyRowView failed",err);
119 for (j=0; j<NumIndices; j++) ++CurrentStart[Indices_[j]];
125 MaxNumEntries_ = orig.MaxNumEntries();
126 delete [] Indices_;
delete [] Values_;
127 Indices_ =
new int[MaxNumEntries_];
128 Values_ =
new double[MaxNumEntries_];
130 for (i=0; i<NumMyRows_; i++)
132 err = orig.ExtractMyRowCopy(i, MaxNumEntries_, NumIndices, Values_, Indices_);
134 std::cerr <<
"ExtractMyRowCopy failed."<<std::endl;
137 for (j=0; j<NumIndices; j++) ++CurrentStart[Indices_[j]];
143 for (i=1;i<NumMyCols_+1; i++) TransRowptr[i] = CurrentStart[i-1] + TransRowptr[i-1];
144 for (i=0;i<NumMyCols_; i++) CurrentStart[i] = TransRowptr[i];
147 for (i=0; i<NumMyRows_; i++)
149 if (OrigMatrixIsCrsMatrix_)
150 err = OrigCrsMatrix->ExtractMyRowView(i, NumIndices, Values_, Indices_);
152 err = orig.ExtractMyRowCopy(i, MaxNumEntries_, NumIndices, Values_, Indices_);
154 std::cerr <<
"ExtractMyRowCopy failed."<<std::endl;
158 for (j=0; j<NumIndices; j++)
160 int idx = CurrentStart[Indices_[j]];
161 TransColind[idx] = i;
162 TransVals[idx] = Values_[j];
163 ++CurrentStart[Indices_[j]];
167 #ifdef ENABLE_TRANSPOSE_TIMINGS 169 mtime=MM.getNewTimer(
"Transpose: BuildTempTrans 2");
175 Epetra_Import * myimport = 0;
176 Epetra_Export * myexport = 0;
177 if(OrigMatrixIsCrsMatrix_ && OrigCrsMatrix->Importer())
178 myexport =
new Epetra_Export(*OrigCrsMatrix->Importer());
179 if(OrigMatrixIsCrsMatrix_ && OrigCrsMatrix->Exporter())
180 myimport =
new Epetra_Import(*OrigCrsMatrix->Exporter());
182 #ifdef ENABLE_TRANSPOSE_TIMINGS 184 mtime=MM.getNewTimer(
"Transpose: BuildTempTrans 3");
189 err = TempTransA1->ExpertStaticFillComplete(orig.OperatorRangeMap(),*TransposeRowMap_,myimport,myexport);
191 throw TempTransA1->ReportError(
"ExpertStaticFillComplete failed.",err);
194 #ifdef ENABLE_TRANSPOSE_TIMINGS 209 if( !TransposeRowMap_ )
211 if( IgnoreNonLocalCols_ )
212 TransposeRowMap_ = (Epetra_Map *) &(orig.OperatorRangeMap());
214 TransposeRowMap_ = (Epetra_Map *) &(orig.OperatorDomainMap());
217 NumMyRows_ = orig.NumMyRows();
218 NumMyCols_ = orig.NumMyCols();
225 Epetra_CrsMatrix * TempTransA1 = BuildTempTrans();
227 if(!TempTransA1->Exporter()) {
229 newObj_ = TransposeMatrix_ = TempTransA1;
233 #ifdef ENABLE_TRANSPOSE_TIMINGS 234 Teuchos::Time myTime(
"global");
235 Teuchos::TimeMonitor MM(myTime);
236 Teuchos::RCP<Teuchos::Time> mtime;
237 mtime=MM.getNewTimer(
"Transpose: Final FusedExport");
243 TransposeMatrix_ =
new Epetra_CrsMatrix(*TempTransA1,*TempTransA1->Exporter(),0,TransposeRowMap_);
245 #ifdef ENABLE_TRANSPOSE_TIMINGS 257 Epetra_CrsMatrix * TempTransA1 = BuildTempTrans();
258 const Epetra_Export * TransposeExporter=0;
259 bool DeleteExporter =
false;
261 if(TempTransA1->Exporter()) TransposeExporter = TempTransA1->Exporter();
264 TransposeExporter =
new Epetra_Export(TransposeMatrix_->DomainMap(),TransposeMatrix_->RowMap());
267 TransposeMatrix_->PutScalar(0.0);
269 EPETRA_CHK_ERR(TransposeMatrix_->Export(*TempTransA1, *TransposeExporter, Add));
271 if(DeleteExporter)
delete TransposeExporter;
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
~RowMatrix_Transpose()
Destructor.
void resize_doubles(int nold, int nnew, double *&d)
NewTypeRef operator()(OriginalTypeRef orig)
Transpose Tranform Operator.
bool fwd()
Foward Data Migration.
bool rvs()
Reverse Data Migration.