int SchwarzSolver::solve() { // compute some statistics for the original problem double condest = -1; Epetra_LinearProblem problem(_stiffnessMatrix.get(), _lhs.get(), _rhs.get()); AztecOO solverForConditionEstimate(problem); solverForConditionEstimate.SetAztecOption(AZ_solver, AZ_cg_condnum); solverForConditionEstimate.ConstructPreconditioner(condest); Epetra_RowMatrix *A = problem.GetMatrix(); double norminf = A->NormInf(); double normone = A->NormOne(); if (_printToConsole) { cout << "\n Inf-norm of stiffness matrix before scaling = " << norminf; cout << "\n One-norm of stiffness matrix before scaling = " << normone << endl << endl; cout << "Condition number estimate: " << condest << endl; } AztecOO solver(problem); int otherRows = A->NumGlobalRows() - A->NumMyRows(); int overlapLevel = std::min(otherRows,_overlapLevel); solver.SetAztecOption(AZ_precond, AZ_dom_decomp); // additive schwarz solver.SetAztecOption(AZ_overlap, overlapLevel); // level of overlap for schwarz solver.SetAztecOption(AZ_type_overlap, AZ_symmetric); solver.SetAztecOption(AZ_solver, AZ_cg_condnum); // more expensive than AZ_cg, but allows estimate of condition # solver.SetAztecOption(AZ_subdomain_solve, AZ_ilut); // TODO: look these up (copied from example) solver.SetAztecParam(AZ_ilut_fill, 1.0); // TODO: look these up (copied from example) solver.SetAztecParam(AZ_drop, 0.0); // TODO: look these up (copied from example) int solveResult = solver.Iterate(_maxIters,_tol); // int solveResult = solver.AdaptiveIterate(_maxIters,1,_tol); // an experiment (was Iterate()) norminf = A->NormInf(); normone = A->NormOne(); condest = solver.Condest(); int numIters = solver.NumIters(); if (_printToConsole) { cout << "\n Inf-norm of stiffness matrix after scaling = " << norminf; cout << "\n One-norm of stiffness matrix after scaling = " << normone << endl << endl; cout << "Condition number estimate: " << condest << endl; cout << "Num iterations: " << numIters << endl; } return solveResult; }
int check(Epetra_RowMatrix& A, Epetra_RowMatrix & B, bool verbose) { int ierr = 0; EPETRA_TEST_ERR(!A.Comm().NumProc()==B.Comm().NumProc(),ierr); EPETRA_TEST_ERR(!A.Comm().MyPID()==B.Comm().MyPID(),ierr); EPETRA_TEST_ERR(!A.Filled()==B.Filled(),ierr); EPETRA_TEST_ERR(!A.HasNormInf()==B.HasNormInf(),ierr); EPETRA_TEST_ERR(!A.LowerTriangular()==B.LowerTriangular(),ierr); EPETRA_TEST_ERR(!A.Map().SameAs(B.Map()),ierr); EPETRA_TEST_ERR(!A.MaxNumEntries()==B.MaxNumEntries(),ierr); EPETRA_TEST_ERR(!A.NumGlobalCols64()==B.NumGlobalCols64(),ierr); EPETRA_TEST_ERR(!A.NumGlobalDiagonals64()==B.NumGlobalDiagonals64(),ierr); EPETRA_TEST_ERR(!A.NumGlobalNonzeros64()==B.NumGlobalNonzeros64(),ierr); EPETRA_TEST_ERR(!A.NumGlobalRows64()==B.NumGlobalRows64(),ierr); EPETRA_TEST_ERR(!A.NumMyCols()==B.NumMyCols(),ierr); EPETRA_TEST_ERR(!A.NumMyDiagonals()==B.NumMyDiagonals(),ierr); EPETRA_TEST_ERR(!A.NumMyNonzeros()==B.NumMyNonzeros(),ierr); for (int i=0; i<A.NumMyRows(); i++) { int nA, nB; A.NumMyRowEntries(i,nA); B.NumMyRowEntries(i,nB); EPETRA_TEST_ERR(!nA==nB,ierr); } EPETRA_TEST_ERR(!A.NumMyRows()==B.NumMyRows(),ierr); EPETRA_TEST_ERR(!A.OperatorDomainMap().SameAs(B.OperatorDomainMap()),ierr); EPETRA_TEST_ERR(!A.OperatorRangeMap().SameAs(B.OperatorRangeMap()),ierr); EPETRA_TEST_ERR(!A.RowMatrixColMap().SameAs(B.RowMatrixColMap()),ierr); EPETRA_TEST_ERR(!A.RowMatrixRowMap().SameAs(B.RowMatrixRowMap()),ierr); EPETRA_TEST_ERR(!A.UpperTriangular()==B.UpperTriangular(),ierr); EPETRA_TEST_ERR(!A.UseTranspose()==B.UseTranspose(),ierr); int NumVectors = 5; { // No transpose case Epetra_MultiVector X(A.OperatorDomainMap(), NumVectors); Epetra_MultiVector YA1(A.OperatorRangeMap(), NumVectors); Epetra_MultiVector YA2(YA1); Epetra_MultiVector YB1(YA1); Epetra_MultiVector YB2(YA1); X.Random(); bool transA = false; A.SetUseTranspose(transA); B.SetUseTranspose(transA); A.Apply(X,YA1); A.Multiply(transA, X, YA2); EPETRA_TEST_ERR(checkMultiVectors(YA1,YA2,"A Multiply and A Apply", verbose),ierr); B.Apply(X,YB1); EPETRA_TEST_ERR(checkMultiVectors(YA1,YB1,"A Multiply and B Multiply", verbose),ierr); B.Multiply(transA, X, YB2); EPETRA_TEST_ERR(checkMultiVectors(YA1,YB2,"A Multiply and B Apply", verbose), ierr); } {// transpose case Epetra_MultiVector X(A.OperatorRangeMap(), NumVectors); Epetra_MultiVector YA1(A.OperatorDomainMap(), NumVectors); Epetra_MultiVector YA2(YA1); Epetra_MultiVector YB1(YA1); Epetra_MultiVector YB2(YA1); X.Random(); bool transA = true; A.SetUseTranspose(transA); B.SetUseTranspose(transA); A.Apply(X,YA1); A.Multiply(transA, X, YA2); EPETRA_TEST_ERR(checkMultiVectors(YA1,YA2, "A Multiply and A Apply (transpose)", verbose),ierr); B.Apply(X,YB1); EPETRA_TEST_ERR(checkMultiVectors(YA1,YB1, "A Multiply and B Multiply (transpose)", verbose),ierr); B.Multiply(transA, X,YB2); EPETRA_TEST_ERR(checkMultiVectors(YA1,YB2, "A Multiply and B Apply (transpose)", verbose),ierr); } Epetra_Vector diagA(A.RowMatrixRowMap()); EPETRA_TEST_ERR(A.ExtractDiagonalCopy(diagA),ierr); Epetra_Vector diagB(B.RowMatrixRowMap()); EPETRA_TEST_ERR(B.ExtractDiagonalCopy(diagB),ierr); EPETRA_TEST_ERR(checkMultiVectors(diagA,diagB, "ExtractDiagonalCopy", verbose),ierr); Epetra_Vector rowA(A.RowMatrixRowMap()); EPETRA_TEST_ERR(A.InvRowSums(rowA),ierr); Epetra_Vector rowB(B.RowMatrixRowMap()); EPETRA_TEST_ERR(B.InvRowSums(rowB),ierr) EPETRA_TEST_ERR(checkMultiVectors(rowA,rowB, "InvRowSums", verbose),ierr); Epetra_Vector colA(A.RowMatrixColMap()); EPETRA_TEST_ERR(A.InvColSums(colA),ierr); Epetra_Vector colB(B.RowMatrixColMap()); EPETRA_TEST_ERR(B.InvColSums(colB),ierr); EPETRA_TEST_ERR(checkMultiVectors(colA,colB, "InvColSums", verbose),ierr); EPETRA_TEST_ERR(checkValues(A.NormInf(), B.NormInf(), "NormInf before scaling", verbose), ierr); EPETRA_TEST_ERR(checkValues(A.NormOne(), B.NormOne(), "NormOne before scaling", verbose),ierr); EPETRA_TEST_ERR(A.RightScale(colA),ierr); EPETRA_TEST_ERR(B.RightScale(colB),ierr); EPETRA_TEST_ERR(A.LeftScale(rowA),ierr); EPETRA_TEST_ERR(B.LeftScale(rowB),ierr); EPETRA_TEST_ERR(checkValues(A.NormInf(), B.NormInf(), "NormInf after scaling", verbose), ierr); EPETRA_TEST_ERR(checkValues(A.NormOne(), B.NormOne(), "NormOne after scaling", verbose),ierr); vector<double> valuesA(A.MaxNumEntries()); vector<int> indicesA(A.MaxNumEntries()); vector<double> valuesB(B.MaxNumEntries()); vector<int> indicesB(B.MaxNumEntries()); return(0); for (int i=0; i<A.NumMyRows(); i++) { int nA, nB; EPETRA_TEST_ERR(A.ExtractMyRowCopy(i, A.MaxNumEntries(), nA, &valuesA[0], &indicesA[0]),ierr); EPETRA_TEST_ERR(B.ExtractMyRowCopy(i, B.MaxNumEntries(), nB, &valuesB[0], &indicesB[0]),ierr); EPETRA_TEST_ERR(!nA==nB,ierr); for (int j=0; j<nA; j++) { double curVal = valuesA[j]; int curIndex = indicesA[j]; bool notfound = true; int jj = 0; while (notfound && jj< nB) { if (!checkValues(curVal, valuesB[jj])) notfound = false; jj++; } EPETRA_TEST_ERR(notfound, ierr); vector<int>::iterator p = find(indicesB.begin(),indicesB.end(),curIndex); // find curIndex in indicesB EPETRA_TEST_ERR(p==indicesB.end(), ierr); } } if (verbose) cout << "RowMatrix Methods check OK" << endl; return (ierr); }
void AZOO_iterate(double * xsolve, double * b, int * options, double * params, double * status, int *proc_config, AZ_MATRIX * Amat, AZ_PRECOND *precond, struct AZ_SCALING *scaling) { (void)precond; (void)scaling; bool verbose = (options[AZ_output]!=AZ_none); // Print info unless all output is turned off Epetra_Comm * comm; Epetra_BlockMap * map; Epetra_RowMatrix * A; Epetra_Vector * px; Epetra_Vector * pb; int * global_indices; int ierr = Aztec2Petra(proc_config, Amat, xsolve, b, comm, map, A, px, pb, &global_indices); if (ierr!=0) { cerr << "Error detected in Aztec2Petra. Value = " << ierr << endl; exit(1); } Epetra_LinearProblem problem(A, px, pb); Epetra_Vector * leftScaleVec = 0; Epetra_Vector * rightScaleVec = 0; bool doRowScaling = false; bool doColScaling = false; if ((options[AZ_scaling]==AZ_Jacobi) || options[AZ_scaling]==AZ_BJacobi) { doRowScaling = true; leftScaleVec = new Epetra_Vector(*map); A->ExtractDiagonalCopy(*leftScaleVec); // Extract diagonal of matrix leftScaleVec->Reciprocal(*leftScaleVec); // invert it } else if (options[AZ_scaling]==AZ_row_sum) { doRowScaling = true; leftScaleVec = new Epetra_Vector(*map); A->InvRowSums(*leftScaleVec); } else if (options[AZ_scaling]==AZ_sym_diag) { doRowScaling = true; doColScaling = true; leftScaleVec = new Epetra_Vector(*map); A->ExtractDiagonalCopy(*leftScaleVec); // Extract diagonal of matrix int length = leftScaleVec->MyLength(); for (int i=0; i<length; i++) (*leftScaleVec)[i] = sqrt(fabs((*leftScaleVec)[i])); // Take its sqrt rightScaleVec = leftScaleVec; // symmetric, so left and right the same leftScaleVec->Reciprocal(*leftScaleVec); // invert it } else if (options[AZ_scaling]==AZ_sym_row_sum) { doRowScaling = true; doColScaling = true; leftScaleVec = new Epetra_Vector(*map); A->InvRowSums(*leftScaleVec); int length = leftScaleVec->MyLength(); for (int i=0; i<length; i++) (*leftScaleVec)[i] = sqrt(fabs((*leftScaleVec)[i])); // Take its sqrt rightScaleVec = leftScaleVec; // symmetric, so left and right the same } if ((doRowScaling || doColScaling) && verbose) { double norminf = A->NormInf(); double normone = A->NormOne(); if (comm->MyPID()==0) cout << "\n Inf-norm of A before scaling = " << norminf << "\n One-norm of A before scaling = " << normone<< endl << endl; } if (doRowScaling) problem.LeftScale(*leftScaleVec); if (doColScaling) problem.RightScale(*rightScaleVec); if ((doRowScaling || doColScaling) && verbose) { double norminf = A->NormInf(); double normone = A->NormOne(); if (comm->MyPID()==0) cout << "\n Inf-norm of A after scaling = " << norminf << "\n One-norm of A after scaling = " << normone << endl << endl; } AztecOO solver(problem); solver.SetAllAztecParams(params); // set all AztecOO params with user-provided params solver.SetAllAztecOptions(options); // set all AztecOO options with user-provided options solver.CheckInput(); solver.SetAztecOption(AZ_scaling, AZ_none); // Always must have scaling off solver.Iterate(options[AZ_max_iter], params[AZ_tol]); solver.GetAllAztecStatus(status); if (doColScaling) { rightScaleVec->Reciprocal(*rightScaleVec); problem.RightScale(*rightScaleVec); } if (doRowScaling) { leftScaleVec->Reciprocal(*leftScaleVec); problem.LeftScale(*leftScaleVec); } if ((rightScaleVec!=0) && (rightScaleVec!=leftScaleVec)) delete rightScaleVec; if (leftScaleVec!=0) delete leftScaleVec; delete pb; // These are all objects created here and we have to delete them delete px; delete A; delete map; delete comm; if (global_indices!=0) AZ_free((void *) global_indices); // Note: we used a special version of free here return; }
int Ifpack_Analyze(const Epetra_RowMatrix& A, const bool Cheap, const int NumPDEEqns) { int NumMyRows = A.NumMyRows(); long long NumGlobalRows = A.NumGlobalRows64(); long long NumGlobalCols = A.NumGlobalCols64(); long long MyBandwidth = 0, GlobalBandwidth; long long MyLowerNonzeros = 0, MyUpperNonzeros = 0; long long GlobalLowerNonzeros, GlobalUpperNonzeros; long long MyDiagonallyDominant = 0, GlobalDiagonallyDominant; long long MyWeaklyDiagonallyDominant = 0, GlobalWeaklyDiagonallyDominant; double MyMin, MyAvg, MyMax; double GlobalMin, GlobalAvg, GlobalMax; long long GlobalStorage; bool verbose = (A.Comm().MyPID() == 0); GlobalStorage = sizeof(int*) * NumGlobalRows + sizeof(int) * A.NumGlobalNonzeros64() + sizeof(double) * A.NumGlobalNonzeros64(); if (verbose) { print(); Ifpack_PrintLine(); print<const char*>("Label", A.Label()); print<long long>("Global rows", NumGlobalRows); print<long long>("Global columns", NumGlobalCols); print<long long>("Stored nonzeros", A.NumGlobalNonzeros64()); print<long long>("Nonzeros / row", A.NumGlobalNonzeros64() / NumGlobalRows); print<double>("Estimated storage (Mbytes)", 1.0e-6 * GlobalStorage); } long long NumMyActualNonzeros = 0, NumGlobalActualNonzeros; long long NumMyEmptyRows = 0, NumGlobalEmptyRows; long long NumMyDirichletRows = 0, NumGlobalDirichletRows; std::vector<int> colInd(A.MaxNumEntries()); std::vector<double> colVal(A.MaxNumEntries()); Epetra_Vector Diag(A.RowMatrixRowMap()); Epetra_Vector RowSum(A.RowMatrixRowMap()); Diag.PutScalar(0.0); RowSum.PutScalar(0.0); for (int i = 0 ; i < NumMyRows ; ++i) { long long GRID = A.RowMatrixRowMap().GID64(i); int Nnz; IFPACK_CHK_ERR(A.ExtractMyRowCopy(i,A.MaxNumEntries(),Nnz, &colVal[0],&colInd[0])); if (Nnz == 0) NumMyEmptyRows++; if (Nnz == 1) NumMyDirichletRows++; for (int j = 0 ; j < Nnz ; ++j) { double v = colVal[j]; if (v < 0) v = -v; if (colVal[j] != 0.0) NumMyActualNonzeros++; long long GCID = A.RowMatrixColMap().GID64(colInd[j]); if (GCID != GRID) RowSum[i] += v; else Diag[i] = v; if (GCID < GRID) MyLowerNonzeros++; else if (GCID > GRID) MyUpperNonzeros++; long long b = GCID - GRID; if (b < 0) b = -b; if (b > MyBandwidth) MyBandwidth = b; } if (Diag[i] > RowSum[i]) MyDiagonallyDominant++; if (Diag[i] >= RowSum[i]) MyWeaklyDiagonallyDominant++; RowSum[i] += Diag[i]; } // ======================== // // summing up global values // // ======================== // A.Comm().SumAll(&MyDiagonallyDominant,&GlobalDiagonallyDominant,1); A.Comm().SumAll(&MyWeaklyDiagonallyDominant,&GlobalWeaklyDiagonallyDominant,1); A.Comm().SumAll(&NumMyActualNonzeros, &NumGlobalActualNonzeros, 1); A.Comm().SumAll(&NumMyEmptyRows, &NumGlobalEmptyRows, 1); A.Comm().SumAll(&NumMyDirichletRows, &NumGlobalDirichletRows, 1); A.Comm().SumAll(&MyBandwidth, &GlobalBandwidth, 1); A.Comm().SumAll(&MyLowerNonzeros, &GlobalLowerNonzeros, 1); A.Comm().SumAll(&MyUpperNonzeros, &GlobalUpperNonzeros, 1); A.Comm().SumAll(&MyDiagonallyDominant, &GlobalDiagonallyDominant, 1); A.Comm().SumAll(&MyWeaklyDiagonallyDominant, &GlobalWeaklyDiagonallyDominant, 1); double NormOne = A.NormOne(); double NormInf = A.NormInf(); double NormF = Ifpack_FrobeniusNorm(A); if (verbose) { print(); print<long long>("Actual nonzeros", NumGlobalActualNonzeros); print<long long>("Nonzeros in strict lower part", GlobalLowerNonzeros); print<long long>("Nonzeros in strict upper part", GlobalUpperNonzeros); print(); print<long long>("Empty rows", NumGlobalEmptyRows, 100.0 * NumGlobalEmptyRows / NumGlobalRows); print<long long>("Dirichlet rows", NumGlobalDirichletRows, 100.0 * NumGlobalDirichletRows / NumGlobalRows); print<long long>("Diagonally dominant rows", GlobalDiagonallyDominant, 100.0 * GlobalDiagonallyDominant / NumGlobalRows); print<long long>("Weakly diag. dominant rows", GlobalWeaklyDiagonallyDominant, 100.0 * GlobalWeaklyDiagonallyDominant / NumGlobalRows); print(); print<long long>("Maximum bandwidth", GlobalBandwidth); print(); print("", "one-norm", "inf-norm", "Frobenius", false); print("", "========", "========", "=========", false); print(); print<double>("A", NormOne, NormInf, NormF); } if (Cheap == false) { // create A + A^T and A - A^T Epetra_FECrsMatrix AplusAT(Copy, A.RowMatrixRowMap(), 0); Epetra_FECrsMatrix AminusAT(Copy, A.RowMatrixRowMap(), 0); #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES if(A.RowMatrixRowMap().GlobalIndicesInt()) { for (int i = 0 ; i < NumMyRows ; ++i) { int GRID = A.RowMatrixRowMap().GID(i); assert (GRID != -1); int Nnz; IFPACK_CHK_ERR(A.ExtractMyRowCopy(i,A.MaxNumEntries(),Nnz, &colVal[0],&colInd[0])); for (int j = 0 ; j < Nnz ; ++j) { int GCID = A.RowMatrixColMap().GID(colInd[j]); assert (GCID != -1); double plus_val = colVal[j]; double minus_val = -colVal[j]; if (AplusAT.SumIntoGlobalValues(1,&GRID,1,&GCID,&plus_val) != 0) { IFPACK_CHK_ERR(AplusAT.InsertGlobalValues(1,&GRID,1,&GCID,&plus_val)); } if (AplusAT.SumIntoGlobalValues(1,&GCID,1,&GRID,&plus_val) != 0) { IFPACK_CHK_ERR(AplusAT.InsertGlobalValues(1,&GCID,1,&GRID,&plus_val)); } if (AminusAT.SumIntoGlobalValues(1,&GRID,1,&GCID,&plus_val) != 0) { IFPACK_CHK_ERR(AminusAT.InsertGlobalValues(1,&GRID,1,&GCID,&plus_val)); } if (AminusAT.SumIntoGlobalValues(1,&GCID,1,&GRID,&minus_val) != 0) { IFPACK_CHK_ERR(AminusAT.InsertGlobalValues(1,&GCID,1,&GRID,&minus_val)); } } } } else #endif #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES if(A.RowMatrixRowMap().GlobalIndicesLongLong()) { for (int i = 0 ; i < NumMyRows ; ++i) { long long GRID = A.RowMatrixRowMap().GID64(i); assert (GRID != -1); int Nnz; IFPACK_CHK_ERR(A.ExtractMyRowCopy(i,A.MaxNumEntries(),Nnz, &colVal[0],&colInd[0])); for (int j = 0 ; j < Nnz ; ++j) { long long GCID = A.RowMatrixColMap().GID64(colInd[j]); assert (GCID != -1); double plus_val = colVal[j]; double minus_val = -colVal[j]; if (AplusAT.SumIntoGlobalValues(1,&GRID,1,&GCID,&plus_val) != 0) { IFPACK_CHK_ERR(AplusAT.InsertGlobalValues(1,&GRID,1,&GCID,&plus_val)); } if (AplusAT.SumIntoGlobalValues(1,&GCID,1,&GRID,&plus_val) != 0) { IFPACK_CHK_ERR(AplusAT.InsertGlobalValues(1,&GCID,1,&GRID,&plus_val)); } if (AminusAT.SumIntoGlobalValues(1,&GRID,1,&GCID,&plus_val) != 0) { IFPACK_CHK_ERR(AminusAT.InsertGlobalValues(1,&GRID,1,&GCID,&plus_val)); } if (AminusAT.SumIntoGlobalValues(1,&GCID,1,&GRID,&minus_val) != 0) { IFPACK_CHK_ERR(AminusAT.InsertGlobalValues(1,&GCID,1,&GRID,&minus_val)); } } } } else #endif throw "Ifpack_Analyze: GlobalIndices type unknown"; AplusAT.FillComplete(); AminusAT.FillComplete(); AplusAT.Scale(0.5); AminusAT.Scale(0.5); NormOne = AplusAT.NormOne(); NormInf = AplusAT.NormInf(); NormF = Ifpack_FrobeniusNorm(AplusAT); if (verbose) { print<double>("A + A^T", NormOne, NormInf, NormF); } NormOne = AminusAT.NormOne(); NormInf = AminusAT.NormInf(); NormF = Ifpack_FrobeniusNorm(AminusAT); if (verbose) { print<double>("A - A^T", NormOne, NormInf, NormF); } } if (verbose) { print(); print<const char*>("", "min", "avg", "max", false); print<const char*>("", "===", "===", "===", false); } MyMax = -DBL_MAX; MyMin = DBL_MAX; MyAvg = 0.0; for (int i = 0 ; i < NumMyRows ; ++i) { int Nnz; IFPACK_CHK_ERR(A.ExtractMyRowCopy(i,A.MaxNumEntries(),Nnz, &colVal[0],&colInd[0])); for (int j = 0 ; j < Nnz ; ++j) { MyAvg += colVal[j]; if (colVal[j] > MyMax) MyMax = colVal[j]; if (colVal[j] < MyMin) MyMin = colVal[j]; } } A.Comm().MaxAll(&MyMax, &GlobalMax, 1); A.Comm().MinAll(&MyMin, &GlobalMin, 1); A.Comm().SumAll(&MyAvg, &GlobalAvg, 1); GlobalAvg /= A.NumGlobalNonzeros64(); if (verbose) { print(); print<double>(" A(i,j)", GlobalMin, GlobalAvg, GlobalMax); } MyMax = 0.0; MyMin = DBL_MAX; MyAvg = 0.0; for (int i = 0 ; i < NumMyRows ; ++i) { int Nnz; IFPACK_CHK_ERR(A.ExtractMyRowCopy(i,A.MaxNumEntries(),Nnz, &colVal[0],&colInd[0])); for (int j = 0 ; j < Nnz ; ++j) { double v = colVal[j]; if (v < 0) v = -v; MyAvg += v; if (colVal[j] > MyMax) MyMax = v; if (colVal[j] < MyMin) MyMin = v; } } A.Comm().MaxAll(&MyMax, &GlobalMax, 1); A.Comm().MinAll(&MyMin, &GlobalMin, 1); A.Comm().SumAll(&MyAvg, &GlobalAvg, 1); GlobalAvg /= A.NumGlobalNonzeros64(); if (verbose) { print<double>("|A(i,j)|", GlobalMin, GlobalAvg, GlobalMax); } // ================= // // diagonal elements // // ================= // Diag.MinValue(&GlobalMin); Diag.MaxValue(&GlobalMax); Diag.MeanValue(&GlobalAvg); if (verbose) { print(); print<double>(" A(k,k)", GlobalMin, GlobalAvg, GlobalMax); } Diag.Abs(Diag); Diag.MinValue(&GlobalMin); Diag.MaxValue(&GlobalMax); Diag.MeanValue(&GlobalAvg); if (verbose) { print<double>("|A(k,k)|", GlobalMin, GlobalAvg, GlobalMax); } // ============================================== // // cycle over all equations for diagonal elements // // ============================================== // if (NumPDEEqns > 1 ) { if (verbose) print(); for (int ie = 0 ; ie < NumPDEEqns ; ie++) { MyMin = DBL_MAX; MyMax = -DBL_MAX; MyAvg = 0.0; for (int i = ie ; i < Diag.MyLength() ; i += NumPDEEqns) { double d = Diag[i]; MyAvg += d; if (d < MyMin) MyMin = d; if (d > MyMax) MyMax = d; } A.Comm().MinAll(&MyMin, &GlobalMin, 1); A.Comm().MaxAll(&MyMax, &GlobalMax, 1); A.Comm().SumAll(&MyAvg, &GlobalAvg, 1); // does not really work fine if the number of global // elements is not a multiple of NumPDEEqns GlobalAvg /= (Diag.GlobalLength64() / NumPDEEqns); if (verbose) { char str[80]; sprintf(str, " A(k,k), eq %d", ie); print<double>(str, GlobalMin, GlobalAvg, GlobalMax); } } } // ======== // // row sums // // ======== // RowSum.MinValue(&GlobalMin); RowSum.MaxValue(&GlobalMax); RowSum.MeanValue(&GlobalAvg); if (verbose) { print(); print<double>(" sum_j A(k,j)", GlobalMin, GlobalAvg, GlobalMax); } // ===================================== // // cycle over all equations for row sums // // ===================================== // if (NumPDEEqns > 1 ) { if (verbose) print(); for (int ie = 0 ; ie < NumPDEEqns ; ie++) { MyMin = DBL_MAX; MyMax = -DBL_MAX; MyAvg = 0.0; for (int i = ie ; i < Diag.MyLength() ; i += NumPDEEqns) { double d = RowSum[i]; MyAvg += d; if (d < MyMin) MyMin = d; if (d > MyMax) MyMax = d; } A.Comm().MinAll(&MyMin, &GlobalMin, 1); A.Comm().MaxAll(&MyMax, &GlobalMax, 1); A.Comm().SumAll(&MyAvg, &GlobalAvg, 1); // does not really work fine if the number of global // elements is not a multiple of NumPDEEqns GlobalAvg /= (Diag.GlobalLength64() / NumPDEEqns); if (verbose) { char str[80]; sprintf(str, " sum_j A(k,j), eq %d", ie); print<double>(str, GlobalMin, GlobalAvg, GlobalMax); } } } if (verbose) Ifpack_PrintLine(); return(0); }