45 #include <Epetra_Import.h> 46 #include <Epetra_CrsMatrix.h> 47 #include <Epetra_CrsGraph.h> 48 #include <Epetra_Map.h> 54 #define MATTRANS_F77 F77_FUNC(mattrans,MATTRANS) 55 #define GENBTF_F77 F77_FUNC(genbtf,GENBTF) 58 extern void MATTRANS_F77(
int*,
int*,
int*,
int*,
int*,
int* );
59 extern void GENBTF_F77(
int*,
int*,
int*,
int*,
int*,
int*,
int*,
int*,
int*,
60 int*,
int*,
int*,
int*,
int*,
int*,
int*,
int*,
int*,
69 if( NewRowMap_ )
delete NewRowMap_;
70 if( NewColMap_ )
delete NewColMap_;
72 if( Importer_ )
delete Importer_;
74 if( NewMatrix_ )
delete NewMatrix_;
75 if( NewGraph_ )
delete NewGraph_;
84 if( orig.RowMap().DistributedGlobal() )
85 { cout <<
"FAIL for Global!\n"; abort(); }
86 if( orig.IndicesAreGlobal() )
87 { cout <<
"FAIL for Global Indices!\n"; abort(); }
89 int n = orig.NumMyRows();
90 int nnz = orig.NumMyNonzeros();
94 cout <<
"Orig Matrix:\n";
100 vector<int> ia(n+1,0);
101 int maxEntries = orig.MaxNumEntries();
102 vector<int> ja_tmp(maxEntries);
103 vector<double> jva_tmp(maxEntries);
107 const Epetra_BlockMap & OldRowMap = orig.RowMap();
108 const Epetra_BlockMap & OldColMap = orig.ColMap();
109 Epetra_CrsGraph strippedGraph( Copy, OldRowMap, OldColMap, 0 );
111 for(
int i = 0; i < n; ++i )
113 orig.ExtractMyRowCopy( i, maxEntries, cnt, &jva_tmp[0], &ja_tmp[0] );
115 for(
int j = 0; j < cnt; ++j )
116 if( fabs(jva_tmp[j]) > threshold_ )
117 ja[ ia[i+1]++ ] = ja_tmp[j];
119 int new_cnt = ia[i+1] - ia[i];
120 strippedGraph.InsertMyIndices( i, new_cnt, &ja[ ia[i] ] );
123 strippedGraph.FillComplete();
127 cout <<
"Stripped Graph\n";
128 cout << strippedGraph;
131 vector<int> iat(n+1,0);
132 vector<int> jat(nnz);
133 for(
int i = 0; i < n; ++i )
134 for(
int j = ia[i]; j < ia[i+1]; ++j )
136 for(
int i = 0; i < n; ++i )
138 for(
int i = 0; i < n; ++i )
139 for(
int j = ia[i]; j < ia[i+1]; ++j )
140 jat[ iat[ ja[j] ]++ ] = i;
141 for(
int i = 0; i < n; ++i )
142 iat[n-i] = iat[n-i-1];
146 for(
int i = 0; i < n+1; ++i ) ++ia[i];
147 for(
int i = 0; i < nnz; ++i ) ++ja[i];
148 for(
int i = 0; i < n+1; ++i ) ++iat[i];
149 for(
int i = 0; i < nnz; ++i ) ++jat[i];
153 cout <<
"-----------------------------------------\n";
154 cout <<
"CRS Format Graph\n";
155 cout <<
"-----------------------------------------\n";
156 for(
int i = 0; i < n; ++i )
158 cout << i+1 <<
": " << ia[i+1] <<
": ";
159 for(
int j = ia[i]-1; j<ia[i+1]-1; ++j )
160 cout <<
" " << ja[j];
163 cout <<
"-----------------------------------------\n";
178 cout <<
"-----------------------------------------\n";
179 cout <<
"CCS Format Graph\n";
180 cout <<
"-----------------------------------------\n";
181 for(
int i = 0; i < n; ++i )
183 cout << i+1 <<
": " << iat[i+1] <<
": ";
184 for(
int j = iat[i]-1; j<iat[i+1]-1; ++j )
185 cout <<
" " << jat[j];
188 cout <<
"-----------------------------------------\n";
193 vector<int> rowperm(n);
194 vector<int> colperm(n);
197 int nhrows, nhcols, hrzcmp;
201 int nvrows, nvcols, vrtcmp;
203 vector<int> rcmstr(n+1);
204 vector<int> ccmstr(n+1);
209 GENBTF_F77( &n, &n, &iat[0], &jat[0], &ia[0], &ja[0], &w[0],
210 &rowperm[0], &colperm[0], &nhrows, &nhcols,
211 &hrzcmp, &nsrows, &sqcmpn, &nvrows, &nvcols, &vrtcmp,
212 &rcmstr[0], &ccmstr[0], &msglvl, &output );
215 for(
int i = 0; i < n; ++i )
220 for(
int i = 0; (i<n+1) && (rcmstr[i]!=n+1); ++i )
228 cout <<
"-----------------------------------------\n";
229 cout <<
"BTF Output\n";
230 cout <<
"-----------------------------------------\n";
231 cout <<
"RowPerm and ColPerm\n";
232 for(
int i = 0; i<n; ++i )
233 cout << rowperm[i] <<
"\t" << colperm[i] << endl;
236 cout <<
"Num Horizontal: Rows, Cols, Comps\n";
237 cout << nhrows <<
"\t" << nhcols <<
"\t" << hrzcmp << endl;
239 cout <<
"Num Square: Rows, Comps\n";
240 cout << nsrows <<
"\t" << sqcmpn << endl;
243 cout <<
"Num Vertical: Rows, Cols, Comps\n";
244 cout << nvrows <<
"\t" << nvcols <<
"\t" << vrtcmp << endl;
246 cout <<
"Row, Col of upper left pt in blocks\n";
247 for(
int i = 0; (i<n+1) && (rcmstr[i]!=n+1); ++i )
248 cout << i <<
" " << rcmstr[i] <<
" " << ccmstr[i] << endl;
249 cout <<
"-----------------------------------------\n";
252 if( hrzcmp || vrtcmp )
254 cout <<
"FAILED! hrz cmp's:" << hrzcmp <<
" vrtcmp: " << vrtcmp << endl;
260 vector<int> rowperm_t( n );
261 vector<int> colperm_t( n );
262 for(
int i = 0; i < n; ++i )
265 rowperm_t[i] = rowperm[i];
266 colperm_t[i] = colperm[i];
271 vector<int> myElements( n );
272 OldRowMap.MyGlobalElements( &myElements[0] );
274 vector<int> newDomainElements( n );
275 vector<int> newRangeElements( n );
276 for(
int i = 0; i < n; ++i )
278 newDomainElements[ i ] = myElements[ rowperm_t[i] ];
279 newRangeElements[ i ] = myElements[ colperm_t[i] ];
282 NewRowMap_ =
new Epetra_Map( n, n, &newDomainElements[0], OldRowMap.IndexBase(), OldRowMap.Comm() );
283 NewColMap_ =
new Epetra_Map( n, n, &newRangeElements[0], OldColMap.IndexBase(), OldColMap.Comm() );
287 cout <<
"New Row Map\n";
288 cout << *NewRowMap_ << endl;
289 cout <<
"New ColMap\n";
290 cout << *NewColMap_ << endl;
294 NewGraph_ =
new Epetra_CrsGraph( Copy, *NewRowMap_, *NewColMap_, 0 );
295 Importer_ =
new Epetra_Import( *NewRowMap_, OldRowMap );
296 NewGraph_->Import( strippedGraph, *Importer_, Insert );
297 NewGraph_->FillComplete();
300 cout <<
"NewGraph\n";
304 NewMatrix_ =
new Epetra_CrsMatrix( Copy, *NewGraph_ );
305 NewMatrix_->Import( orig, *Importer_, Insert );
306 NewMatrix_->FillComplete();
310 cout <<
"New CrsMatrix\n";
311 cout << *NewMatrix_ << endl;
323 int ret = NewMatrix_->Import( *
origObj_, *Importer_, Insert );
324 if (ret<0)
return false;
332 int ret =
origObj_->Export( *NewMatrix_, *Importer_, Insert );
333 if (ret<0)
return false;
NewTypeRef operator()(OriginalTypeRef orig)
Analysis of transform operation on original object and construction of new object.
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
bool fwd()
Forward transfer of data from orig object input in the operator() method call to the new object creat...
bool rvs()
Reverse transfer of data from new object created in the operator() method call to the orig object inp...