43 #include "Epetra_Map.h" 44 #include "Epetra_Util.h" 45 #include "Epetra_Export.h" 46 #include "Epetra_Import.h" 47 #include "Epetra_MultiVector.h" 48 #include "Epetra_Vector.h" 49 #include "Epetra_IntVector.h" 50 #include "Epetra_Comm.h" 51 #include "Epetra_LinearProblem.h" 52 #include "Epetra_MapColoring.h" 115 cout <<
"\nAnalyzed Singleton Problem:\n";
116 cout <<
"---------------------------\n";
120 cout <<
"Singletons Detected!" << endl;;
126 cout <<
"No Singletons Detected!" << endl;
141 cout <<
"---------------------------\n\n";
160 cout <<
"\nConstructedSingleton Problem:\n";
161 cout <<
"---------------------------\n";
164 cout <<
"---------------------------\n\n";
174 if( ierr ) cout <<
"EDT_LinearProblem_CrsSingletonFilter::UpdateReducedProblem FAILED!\n";
183 if( ierr ) cout <<
"EDT_LinearProblem_CrsSingletonFilter::ComputeFullSolution FAILED!\n";
247 if (FullMatrix==0) EPETRA_CHK_ERR(-2);
248 if (FullMatrix->NumGlobalRows()==0) EPETRA_CHK_ERR(-3);
249 if (FullMatrix->NumGlobalNonzeros()==0) EPETRA_CHK_ERR(-4);
253 Epetra_IntVector ColHasRowWithSingleton(
FullMatrixColMap()); ColHasRowWithSingleton.PutValue(0);
265 int NumMyRows = FullMatrix->NumMyRows();
266 int NumMyCols = FullMatrix->NumMyCols();
275 for (i=0; i<NumMyRows; i++) {
277 EPETRA_CHK_ERR(
GetRow(i, NumIndices, Indices));
278 for (j=0; j<NumIndices; j++) {
279 int ColumnIndex = Indices[j];
280 ColProfiles[ColumnIndex]++;
283 RowIDs[ColumnIndex] = i;
288 ColHasRowWithSingleton[j]++;
304 Epetra_IntVector NewColProfiles(ColProfiles);
308 if (FullMatrix->RowMatrixImporter()!=0) {
310 EPETRA_CHK_ERR(tmpVec.PutValue(0));
311 EPETRA_CHK_ERR(tmpVec.Export(ColProfiles, *FullMatrix->RowMatrixImporter(), Add));
312 EPETRA_CHK_ERR(ColProfiles.Import(tmpVec, *FullMatrix->RowMatrixImporter(), Insert));
314 EPETRA_CHK_ERR(tmpVec.PutValue(0));
315 EPETRA_CHK_ERR(tmpVec.Export(ColHasRowWithSingleton, *FullMatrix->RowMatrixImporter(), Add));
316 EPETRA_CHK_ERR(ColHasRowWithSingleton.Import(tmpVec, *FullMatrix->RowMatrixImporter(), Insert));
323 if (ColHasRowWithSingleton.MaxValue()>1) {
327 Epetra_IntVector RowHasColWithSingleton(FullMatrix->RowMatrixRowMap());
328 RowHasColWithSingleton.PutValue(0);
332 for (j=0; j<NumMyCols; j++) {
335 if (ColProfiles[j]==1 ) {
339 if (RowMapColors[i]!=1) {
340 RowHasColWithSingleton[i]++;
347 EPETRA_CHK_ERR(
GetRow(i, NumIndices, Indices));
348 for (jj=0; jj<NumIndices; jj++) NewColProfiles[Indices[jj]]--;
353 else if (ColHasRowWithSingleton[j]==1 && RowMapColors[i]!=1) {
357 if (RowHasColWithSingleton.MaxValue()>1) {
363 ColHasRowWithSingleton));
365 for (i=0; i<NumMyRows; i++)
if (RowMapColors[i]==2) RowMapColors[i] = 1;
377 if (Problem==0) EPETRA_CHK_ERR(-2);
380 FullMatrix_ =
dynamic_cast<Epetra_RowMatrix *
>(Problem->GetMatrix());
382 if (Problem->GetRHS()==0) EPETRA_CHK_ERR(-4);
383 if (Problem->GetLHS()==0) EPETRA_CHK_ERR(-5);
431 Epetra_MultiVector * FullRHS =
FullProblem()->GetRHS();
432 Epetra_MultiVector * FullLHS =
FullProblem()->GetLHS();
433 int NumVectors = FullLHS->NumVectors();
449 int ColSingletonCounter = 0;
450 for (i=0; i<NumMyRows; i++) {
454 EPETRA_CHK_ERR(
GetRowGCIDs(i, NumEntries, Values, Indices));
456 int ierr =
ReducedMatrix()->InsertGlobalValues(curGRID, NumEntries,
462 if (ierr<0) EPETRA_CHK_ERR(ierr);
465 EPETRA_CHK_ERR(
GetRow(i, NumEntries, Values, Indices));
467 double pivot = Values[0];
468 if (pivot==0.0) EPETRA_CHK_ERR(-1);
469 int indX = Indices[0];
470 for (j=0; j<NumVectors; j++)
477 for (j=0; j<NumEntries; j++) {
478 if (Indices[j]==targetCol) {
479 double pivot = Values[j];
480 if (pivot==0.0) EPETRA_CHK_ERR(-2);
483 ColSingletonCounter++;
501 FullLHS->PutScalar(0.0);
507 tempB_ =
new Epetra_MultiVector(FullRHS->Map(), NumVectors);
523 EPETRA_CHK_ERR(
tempB_->Update(1.0, *FullRHS, -1.0));
535 ReducedMatrix_ = Teuchos::rcp( dynamic_cast<Epetra_CrsMatrix *>(Problem->GetMatrix()),
false );
539 double fnnz =
FullMatrix()->NumGlobalNonzeros();
554 if (Problem==0) EPETRA_CHK_ERR(-1);
557 FullMatrix_ =
dynamic_cast<Epetra_RowMatrix *
>(Problem->GetMatrix());
559 if (Problem->GetRHS()==0) EPETRA_CHK_ERR(-3);
560 if (Problem->GetLHS()==0) EPETRA_CHK_ERR(-4);
566 Epetra_MultiVector * FullRHS =
FullProblem()->GetRHS();
567 Epetra_MultiVector * FullLHS =
FullProblem()->GetLHS();
569 int NumVectors = FullLHS->NumVectors();
576 int ColSingletonCounter = 0;
577 for (i=0; i<NumMyRows; i++) {
580 EPETRA_CHK_ERR(
GetRowGCIDs(i, NumEntries, Values, Indices));
581 int ierr =
ReducedMatrix()->ReplaceGlobalValues(curGRID, NumEntries,
587 if (ierr<0) EPETRA_CHK_ERR(ierr);
591 EPETRA_CHK_ERR(
GetRow(i, NumEntries, Values, Indices));
593 double pivot = Values[0];
594 if (pivot==0.0) EPETRA_CHK_ERR(-1);
595 int indX = Indices[0];
596 for (j=0; j<NumVectors; j++)
603 double pivot = Values[j];
604 if (pivot==0.0) EPETRA_CHK_ERR(-2);
606 ColSingletonCounter++;
617 FullLHS->PutScalar(0.0);
639 EPETRA_CHK_ERR(
tempB_->Update(1.0, *FullRHS, -1.0));
648 ReducedMatrix_ = Teuchos::rcp( dynamic_cast<Epetra_CrsMatrix *>(Problem->GetMatrix()),
false );
655 Epetra_Export * & RedistributeExporter,
656 Epetra_Map * & RedistributeMap) {
658 int IndexBase = SourceMap->IndexBase();
659 if (IndexBase!=TargetMap->IndexBase()) EPETRA_CHK_ERR(-1);
661 const Epetra_Comm & Comm = TargetMap->Comm();
663 int TargetNumMyElements = TargetMap->NumMyElements();
664 int SourceNumMyElements = SourceMap->NumMyElements();
667 Epetra_Map ContiguousTargetMap(-1, TargetNumMyElements, IndexBase,Comm);
670 Epetra_Map ContiguousSourceMap(-1, SourceNumMyElements, IndexBase, Comm);
672 assert(ContiguousSourceMap.NumGlobalElements()==ContiguousTargetMap.NumGlobalElements());
675 Epetra_IntVector SourceIndices(View, ContiguousSourceMap, SourceMap->MyGlobalElements());
678 Epetra_Export Exporter(ContiguousSourceMap, ContiguousTargetMap);
681 Epetra_IntVector TargetIndices(ContiguousTargetMap);
682 TargetIndices.Export(SourceIndices, Exporter, Insert);
686 RedistributeMap =
new Epetra_Map(-1, TargetNumMyElements, TargetIndices.Values(), IndexBase, Comm);
689 RedistributeExporter =
new Epetra_Export(*SourceMap, *RedistributeMap);
698 Epetra_MultiVector * FullLHS =
FullProblem()->GetLHS();
699 Epetra_MultiVector * FullRHS =
FullProblem()->GetRHS();
705 FullLHS->Update(1.0, *
tempX_, 1.0);
716 int NumVectors =
tempB_->NumVectors();
721 for (jj=0; jj<NumVectors; jj++)
722 (*
tempExportX_)[jj][j]= ((*FullRHS)[jj][i] - (*tempB_)[jj][i])/pivot;
734 FullLHS->Update(1.0, *
tempX_, 1.0);
756 EPETRA_CHK_ERR(
FullCrsMatrix()->Graph().ExtractMyRowView(Row, NumIndices, Indices));
767 double * & Values,
int * & Indices) {
770 EPETRA_CHK_ERR(
FullCrsMatrix_->ExtractMyRowView(Row, NumIndices, Values, Indices));
782 double * & Values,
int * & GlobalIndices) {
794 const Epetra_IntVector & ColProfiles,
795 const Epetra_IntVector & NewColProfiles,
796 const Epetra_IntVector & ColHasRowWithSingleton) {
814 int NumMyColSingletonstmp = 0;
815 for (j=0; j<NumMyCols; j++) {
817 if ( ColProfiles[j]==1 && RowMapColors[i]!=1 ) {
820 NumMyColSingletonstmp++;
824 else if (NewColProfiles[j]==0 && ColHasRowWithSingleton[j]!=1 && RowMapColors[i]==0) {
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.