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> 50 #include <Epetra_Comm.h> 62 double *tmp =
new double[nnew];
63 for(
int i=0; i<nold; i++)
86 #ifdef ENABLE_TRANSPOSE_TIMINGS 90 mtime=MM.
getNewTimer(
"Transpose: CreateTransposeLocal 1");
95 const Epetra_CrsMatrix * OrigCrsMatrix =
dynamic_cast<const Epetra_CrsMatrix*
>(&orig);
96 if(OrigCrsMatrix) OrigMatrixIsCrsMatrix_ =
true;
97 else OrigMatrixIsCrsMatrix_ =
false;
99 const Epetra_Map & TransMap = orig.RowMatrixColMap();
100 int TransNnz = orig.NumMyNonzeros();
103 Epetra_CrsMatrix *TempTransA1 =
new Epetra_CrsMatrix(
Copy, TransMap,orig.RowMatrixRowMap(),0);
104 Epetra_IntSerialDenseVector & TransRowptr = TempTransA1->ExpertExtractIndexOffset();
105 Epetra_IntSerialDenseVector & TransColind = TempTransA1->ExpertExtractIndices();
106 double *& TransVals = TempTransA1->ExpertExtractValues();
107 NumMyRows_ = orig.NumMyRows();
108 NumMyCols_ = orig.NumMyCols();
110 TransRowptr.Resize(NumMyCols_+1);
111 TransColind.Resize(TransNnz);
113 std::vector<int> CurrentStart(NumMyCols_,0);
116 if (OrigMatrixIsCrsMatrix_)
118 const Epetra_CrsGraph & OrigGraph = OrigCrsMatrix->Graph();
120 for (i=0; i<NumMyRows_; i++)
122 err = OrigGraph.ExtractMyRowView(i, NumIndices, Indices_);
123 if (err != 0)
throw OrigGraph.ReportError(
"ExtractMyRowView failed",err);
124 for (j=0; j<NumIndices; j++) ++CurrentStart[Indices_[j]];
130 MaxNumEntries_ = orig.MaxNumEntries();
131 delete [] Indices_;
delete [] Values_;
132 Indices_ =
new int[MaxNumEntries_];
133 Values_ =
new double[MaxNumEntries_];
135 for (i=0; i<NumMyRows_; i++)
137 err = orig.ExtractMyRowCopy(i, MaxNumEntries_, NumIndices, Values_, Indices_);
139 std::cerr <<
"ExtractMyRowCopy failed."<<std::endl;
142 for (j=0; j<NumIndices; j++) ++CurrentStart[Indices_[j]];
148 for (i=1;i<NumMyCols_+1; i++) TransRowptr[i] = CurrentStart[i-1] + TransRowptr[i-1];
149 for (i=0;i<NumMyCols_; i++) CurrentStart[i] = TransRowptr[i];
152 for (i=0; i<NumMyRows_; i++)
154 if (OrigMatrixIsCrsMatrix_)
155 err = OrigCrsMatrix->ExtractMyRowView(i, NumIndices, Values_, Indices_);
157 err = orig.ExtractMyRowCopy(i, MaxNumEntries_, NumIndices, Values_, Indices_);
159 std::cerr <<
"ExtractMyRowCopy failed."<<std::endl;
163 for (j=0; j<NumIndices; j++)
165 int idx = CurrentStart[Indices_[j]];
166 TransColind[idx] = i;
167 TransVals[idx] = Values_[j];
168 ++CurrentStart[Indices_[j]];
172 #ifdef ENABLE_TRANSPOSE_TIMINGS 174 mtime=MM.
getNewTimer(
"Transpose: CreateTransposeLocal 2");
180 Epetra_Import * myimport = 0;
181 Epetra_Export * myexport = 0;
182 if(OrigMatrixIsCrsMatrix_ && OrigCrsMatrix->Importer())
183 myexport =
new Epetra_Export(*OrigCrsMatrix->Importer());
184 if(OrigMatrixIsCrsMatrix_ && OrigCrsMatrix->Exporter())
185 myimport =
new Epetra_Import(*OrigCrsMatrix->Exporter());
187 #ifdef ENABLE_TRANSPOSE_TIMINGS 189 mtime=MM.
getNewTimer(
"Transpose: CreateTransposeLocal 3");
194 err = TempTransA1->ExpertStaticFillComplete(orig.OperatorRangeMap(),orig.OperatorDomainMap(),myimport,myexport);
196 throw TempTransA1->ReportError(
"ExpertStaticFillComplete failed.",err);
199 #ifdef ENABLE_TRANSPOSE_TIMINGS 232 if(!TempTransA1->Exporter()) {
238 #ifdef ENABLE_TRANSPOSE_TIMINGS 242 mtime=MM.
getNewTimer(
"Transpose: Final FusedExport");
250 #ifdef ENABLE_TRANSPOSE_TIMINGS 262 Epetra_CrsMatrix * TempTransA1 = CreateTransposeLocal(*origObj_);
263 const Epetra_Export * TransposeExporter=0;
264 bool DeleteExporter =
false;
266 if(TempTransA1->Exporter()) TransposeExporter = TempTransA1->Exporter();
269 TransposeExporter =
new Epetra_Export(TransposeMatrix_->DomainMap(),TransposeMatrix_->RowMap());
272 TransposeMatrix_->PutScalar(0.0);
274 EPETRA_CHK_ERR(TransposeMatrix_->Export(*TempTransA1, *TransposeExporter, Add));
276 if(DeleteExporter)
delete TransposeExporter;
bool OrigMatrixIsCrsMatrix_
Epetra_CrsMatrix * TransposeMatrix_
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
static RCP< Time > getNewTimer(const std::string &name)
~RowMatrix_Transpose()
Destructor.
void resize_doubles(int nold, int nnew, double *&d)
void start(bool reset=false)
NewTypeRef operator()(OriginalTypeRef orig)
Transpose Transform Operator.
Epetra_Map * TransposeRowMap_
bool fwd()
Foward Data Migration.
Epetra_CrsMatrix * CreateTransposeLocal(OriginalTypeRef orig)
Local-only transpose operator. Don't use this unless you're sure you know what you're doing...
bool rvs()
Reverse Data Migration.