本文整理汇总了C++中Epetra_LinearProblem::GetMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_LinearProblem::GetMatrix方法的具体用法?C++ Epetra_LinearProblem::GetMatrix怎么用?C++ Epetra_LinearProblem::GetMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_LinearProblem
的用法示例。
在下文中一共展示了Epetra_LinearProblem::GetMatrix方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: show_matrix
void show_matrix(const char *txt, const Epetra_LinearProblem &problem, const Epetra_Comm &comm)
{
int me = comm.MyPID();
if (comm.NumProc() > 10){
if (me == 0){
std::cout << txt << std::endl;
std::cout << "Printed matrix format only works for 10 or fewer processes" << std::endl;
}
return;
}
Epetra_RowMatrix *matrix = problem.GetMatrix();
Epetra_MultiVector *lhs = problem.GetLHS();
Epetra_MultiVector *rhs = problem.GetRHS();
int numRows = matrix->NumGlobalRows();
int numCols = matrix->NumGlobalCols();
if ((numRows > 200) || (numCols > 500)){
if (me == 0){
std::cerr << txt << std::endl;
std::cerr << "show_matrix: problem is too large to display" << std::endl;
}
return;
}
int *myA = new int [numRows * numCols];
make_my_A(*matrix, myA, comm);
int *myX = new int [numCols];
int *myB = new int [numRows];
memset(myX, 0, sizeof(int) * numCols);
memset(myB, 0, sizeof(int) * numRows);
const Epetra_BlockMap &lhsMap = lhs->Map();
const Epetra_BlockMap &rhsMap = rhs->Map();
int base = lhsMap.IndexBase();
for (int j=0; j < lhsMap.NumMyElements(); j++){
int colGID = lhsMap.GID(j);
myX[colGID - base] = me + 1;
}
for (int i=0; i < rhsMap.NumMyElements(); i++){
int rowGID = rhsMap.GID(i);
myB[rowGID - base] = me + 1;
}
printMatrix(txt, myA, myX, myB, numRows, numCols, comm);
delete [] myA;
delete [] myX;
delete [] myB;
}
示例2: TestMultiLevelPreconditioner
int TestMultiLevelPreconditioner(char ProblemType[],
Teuchos::ParameterList & MLList,
Epetra_LinearProblem & Problem, double & TotalErrorResidual,
double & TotalErrorExactSol,bool cg=false)
{
Epetra_MultiVector* lhs = Problem.GetLHS();
Epetra_MultiVector* rhs = Problem.GetRHS();
Epetra_RowMatrix* A = Problem.GetMatrix();
// ======================================== //
// create a rhs corresponding to lhs or 1's //
// ======================================== //
lhs->PutScalar(1.0);
A->Multiply(false,*lhs,*rhs);
lhs->PutScalar(0.0);
Epetra_Time Time(A->Comm());
// =================== //
// call ML and AztecOO //
// =================== //
AztecOO solver(Problem);
MLList.set("ML output", 10);
ML_Epetra::MultiLevelPreconditioner * MLPrec = new ML_Epetra::MultiLevelPreconditioner(*A, MLList, true);
// tell AztecOO to use this preconditioner, then solve
solver.SetPrecOperator(MLPrec);
if(cg) solver.SetAztecOption(AZ_solver, AZ_cg);
else solver.SetAztecOption(AZ_solver, AZ_gmres);
solver.SetAztecOption(AZ_output, 32);
solver.SetAztecOption(AZ_kspace, 160);
solver.Iterate(1550, 1e-12);
delete MLPrec;
// ==================================================== //
// compute difference between exact solution and ML one //
// ==================================================== //
double d = 0.0, d_tot = 0.0;
for( int i=0 ; i<lhs->Map().NumMyElements() ; ++i )
d += ((*lhs)[0][i] - 1.0) * ((*lhs)[0][i] - 1.0);
A->Comm().SumAll(&d,&d_tot,1);
// ================== //
// compute ||Ax - b|| //
// ================== //
double Norm;
Epetra_Vector Ax(rhs->Map());
A->Multiply(false, *lhs, Ax);
Ax.Update(1.0, *rhs, -1.0);
Ax.Norm2(&Norm);
string msg = ProblemType;
if (A->Comm().MyPID() == 0) {
cout << msg << "......Using " << A->Comm().NumProc() << " processes" << endl;
cout << msg << "......||A x - b||_2 = " << Norm << endl;
cout << msg << "......||x_exact - x||_2 = " << sqrt(d_tot) << endl;
cout << msg << "......Total Time = " << Time.ElapsedTime() << endl;
}
TotalErrorExactSol += sqrt(d_tot);
TotalErrorResidual += Norm;
return( solver.NumIters() );
}
示例3: TestMultiLevelPreconditioner
int TestMultiLevelPreconditioner(char ProblemType[],
Teuchos::ParameterList & MLList,
Epetra_LinearProblem & Problem, double & TotalErrorResidual,
double & TotalErrorExactSol)
{
Epetra_MultiVector* lhs = Problem.GetLHS();
Epetra_MultiVector* rhs = Problem.GetRHS();
Epetra_CrsMatrix* A = dynamic_cast<Epetra_CrsMatrix*>(Problem.GetMatrix());
int PID = A->Comm().MyPID();
int numProcs = A->Comm().NumProc();
RCP<const Epetra_RowMatrix> Arcp = Teuchos::rcp(A, false);
double n1, n2,nf;
// ======================================== //
// create a rhs corresponding to lhs or 1's //
// ======================================== //
lhs->PutScalar(1.0);
A->Multiply(false,*lhs,*rhs);
lhs->PutScalar(0.0);
MLList.set("ML output", 0);
RowMatrixToMatlabFile("mat_f.dat",*A);
MultiVectorToMatrixMarketFile("lhs_f.dat",*lhs,0,0,false);
MultiVectorToMatrixMarketFile("rhs_f.dat",*rhs,0,0,false);
Epetra_Time Time(A->Comm());
/* Build the Zoltan list - Group #1 */
ParameterList Zlist1,Sublist1;
Sublist1.set("DEBUG_LEVEL","0");
Sublist1.set("NUM_GLOBAL_PARTITIONS","2");
Zlist1.set("Zoltan",Sublist1);
/* Start Isorropia's Ninja Magic - Group #1 */
RefCountPtr<Isorropia::Epetra::Partitioner> partitioner1 =
Isorropia::Epetra::create_partitioner(Arcp, Zlist1);
Isorropia::Epetra::Redistributor rd1(partitioner1);
Teuchos::RCP<Epetra_CrsMatrix> ResA1=rd1.redistribute(*A);
Teuchos::RCP<Epetra_MultiVector> ResX1=rd1.redistribute(*lhs);
Teuchos::RCP<Epetra_MultiVector> ResB1=rd1.redistribute(*rhs);
RestrictedCrsMatrixWrapper RW1;
RW1.restrict_comm(ResA1);
RestrictedMultiVectorWrapper RX1,RB1;
RX1.restrict_comm(ResX1);
RB1.restrict_comm(ResB1);
/* Build the Zoltan list - Group #2 */
ParameterList Zlist2,Sublist2;
Sublist2.set("DEBUG_LEVEL","0");
if(PID > 1) Sublist2.set("NUM_LOCAL_PARTITIONS","1");
else Sublist2.set("NUM_LOCAL_PARTITIONS","0");
Zlist2.set("Zoltan",Sublist2);
/* Start Isorropia's Ninja Magic - Group #2 */
RefCountPtr<Isorropia::Epetra::Partitioner> partitioner2 =
Isorropia::Epetra::create_partitioner(Arcp, Zlist2);
Isorropia::Epetra::Redistributor rd2(partitioner2);
Teuchos::RCP<Epetra_CrsMatrix> ResA2=rd2.redistribute(*A);
Teuchos::RCP<Epetra_MultiVector> ResX2=rd2.redistribute(*lhs);
Teuchos::RCP<Epetra_MultiVector> ResB2=rd2.redistribute(*rhs);
RestrictedCrsMatrixWrapper RW2;
RW2.restrict_comm(ResA2);
RestrictedMultiVectorWrapper RX2,RB2;
RX2.restrict_comm(ResX2);
RB2.restrict_comm(ResB2);
if(RW1.RestrictedProcIsActive()){
Teuchos::RCP<Epetra_CrsMatrix> SubA1 = RW1.RestrictedMatrix();
Teuchos::RCP<Epetra_MultiVector> SubX1 = RX1.RestrictedMultiVector();
Teuchos::RCP<Epetra_MultiVector> SubB1 = RB1.RestrictedMultiVector();
ML_Epetra::MultiLevelPreconditioner * SubPrec1 = new ML_Epetra::MultiLevelPreconditioner(*SubA1, MLList, true);
Epetra_LinearProblem Problem1(&*SubA1,&*SubX1,&*SubB1);
AztecOO solver1(Problem1);
solver1.SetPrecOperator(SubPrec1);
solver1.SetAztecOption(AZ_solver, AZ_gmres);
solver1.SetAztecOption(AZ_output, 32);
solver1.SetAztecOption(AZ_kspace, 160);
solver1.Iterate(1550, 1e-12);
delete SubPrec1;
}
else{
Teuchos::RCP<Epetra_CrsMatrix> SubA2 = RW2.RestrictedMatrix();
Teuchos::RCP<Epetra_MultiVector> SubX2 = RX2.RestrictedMultiVector();
Teuchos::RCP<Epetra_MultiVector> SubB2 = RB2.RestrictedMultiVector();
ML_Epetra::MultiLevelPreconditioner * SubPrec2 = new ML_Epetra::MultiLevelPreconditioner(*SubA2, MLList, true);
Epetra_LinearProblem Problem2(&*SubA2,&*SubX2,&*SubB2);
AztecOO solver2(Problem2);
solver2.SetPrecOperator(SubPrec2);
solver2.SetAztecOption(AZ_solver, AZ_gmres);
solver2.SetAztecOption(AZ_output, 32);
//.........这里部分代码省略.........
示例4: CompareWithAztecOO
bool CompareWithAztecOO(Epetra_LinearProblem& Problem, const std::string what,
int Overlap, int ival)
{
using std::cout;
using std::endl;
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,AZ_gmres);
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetAztecOption(AZ_overlap,Overlap);
AztecOOSolver.SetAztecOption(AZ_graph_fill,ival);
AztecOOSolver.SetAztecOption(AZ_poly_ord, ival);
AztecOOSolver.SetAztecParam(AZ_drop, 0.0);
AztecOOSolver.SetAztecParam(AZ_athresh, 0.0);
AztecOOSolver.SetAztecParam(AZ_rthresh, 0.0);
Epetra_MultiVector& RHS = *(Problem.GetRHS());
Epetra_MultiVector& LHS = *(Problem.GetLHS());
Teuchos::RefCountPtr<Epetra_RowMatrix> A = Teuchos::rcp(Problem.GetMatrix(), false);
LHS.Random();
A->Multiply(false,LHS,RHS);
Teuchos::ParameterList List;
List.set("fact: level-of-fill", ival);
List.set("relaxation: sweeps", ival);
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: zero starting solution", true);
//default combine mode is as for AztecOO
List.set("schwarz: combine mode", Zero);
Epetra_Time Time(A->Comm());
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec;
if (what == "Jacobi") {
Prec = Teuchos::rcp( new Ifpack_PointRelaxation(&*A) );
List.set("relaxation: type", "Jacobi");
AztecOOSolver.SetAztecOption(AZ_precond,AZ_Jacobi);
AztecOOSolver.SetAztecOption(AZ_reorder,0);
}
else if (what == "IC no reord") {
Prec = Teuchos::rcp( new Ifpack_AdditiveSchwarz<Ifpack_IC>(&*A,Overlap) );
AztecOOSolver.SetAztecOption(AZ_precond,AZ_dom_decomp);
AztecOOSolver.SetAztecOption(AZ_subdomain_solve,AZ_icc);
AztecOOSolver.SetAztecOption(AZ_reorder,0);
}
else if (what == "IC reord") {
Prec = Teuchos::rcp( new Ifpack_AdditiveSchwarz<Ifpack_IC>(&*A,Overlap) );
List.set("schwarz: use reordering", true);
AztecOOSolver.SetAztecOption(AZ_precond,AZ_dom_decomp);
AztecOOSolver.SetAztecOption(AZ_subdomain_solve,AZ_icc);
AztecOOSolver.SetAztecOption(AZ_reorder,1);
}
else if (what == "ILU no reord") {
Prec = Teuchos::rcp( new Ifpack_AdditiveSchwarz<Ifpack_ILU>(&*A,Overlap) );
AztecOOSolver.SetAztecOption(AZ_precond,AZ_dom_decomp);
AztecOOSolver.SetAztecOption(AZ_subdomain_solve,AZ_ilu);
AztecOOSolver.SetAztecOption(AZ_reorder,0);
}
else if (what == "ILU reord") {
Prec = Teuchos::rcp( new Ifpack_AdditiveSchwarz<Ifpack_ILU>(&*A,Overlap) );
List.set("schwarz: use reordering", true);
AztecOOSolver.SetAztecOption(AZ_precond,AZ_dom_decomp);
AztecOOSolver.SetAztecOption(AZ_subdomain_solve,AZ_ilu);
AztecOOSolver.SetAztecOption(AZ_reorder,1);
}
#ifdef HAVE_IFPACK_AMESOS
else if (what == "LU") {
Prec = Teuchos::rcp( new Ifpack_AdditiveSchwarz<Ifpack_Amesos>(&*A,Overlap) );
List.set("amesos: solver type", "Klu");
AztecOOSolver.SetAztecOption(AZ_precond,AZ_dom_decomp);
AztecOOSolver.SetAztecOption(AZ_subdomain_solve,AZ_lu);
}
#endif
else {
cerr << "Option not recognized" << endl;
exit(EXIT_FAILURE);
}
// ==================================== //
// Solve with AztecOO's preconditioners //
// ==================================== //
LHS.PutScalar(0.0);
Time.ResetStartTime();
AztecOOSolver.Iterate(150,1e-5);
if (verbose) {
cout << endl;
cout << "==================================================" << endl;
cout << "Testing `" << what << "', Overlap = "
<< Overlap << ", ival = " << ival << endl;
cout << endl;
cout << "[AztecOO] Total time = " << Time.ElapsedTime() << " (s)" << endl;
cout << "[AztecOO] Residual = " << AztecOOSolver.TrueResidual() << " (s)" << endl;
cout << "[AztecOO] Iterations = " << AztecOOSolver.NumIters() << endl;
cout << endl;
//.........这里部分代码省略.........
示例5: Solve
// ============================================================================
void
Solve(const Epetra_LinearProblem Problem)
{
Solve(Problem.GetMatrix(), Problem.GetLHS(), Problem.GetRHS());
}
示例6: main
//.........这里部分代码省略.........
Comm.Barrier();
int NumMyElements = 3;
Epetra_Map Map( NumMyElements, 0, Comm );
Epetra_CrsGraph Graph( Copy, Map, 1 );
int index[2];
index[0] = 2;
Graph.InsertGlobalIndices( 0, 1, &index[0] );
index[0] = 0;
index[1] = 2;
Graph.InsertGlobalIndices( 1, 2, &index[0] );
index[0] = 1;
Graph.InsertGlobalIndices( 2, 1, &index[0] );
Graph.FillComplete();
if (verbose) {
cout << "***************** PERFORMING BTF TRANSFORM ON CRS_GRAPH *****************" <<endl<<endl;
cout << "CrsGraph *before* BTF transform: " << endl << endl;
cout << Graph << endl;
}
EpetraExt::AmesosBTF_CrsGraph BTFTrans( true, verbose );
Epetra_CrsGraph & NewBTFGraph = BTFTrans( Graph );
if (verbose) {
cout << "CrsGraph *after* BTF transform: " << endl << endl;
cout << NewBTFGraph << endl;
}
// Use BTF graph transformation to solve linear system.
// Create an Epetra::CrsMatrix
Epetra_CrsMatrix Matrix( Copy, Graph );
double value[2];
index[0] = 2; value[0] = 3.0;
Matrix.ReplaceMyValues( 0, 1, &value[0], &index[0] );
index[0] = 0; index[1] = 2;
value[0] = 2.0; value[1] = 2.5;
Matrix.ReplaceMyValues( 1, 2, &value[0], &index[0] );
index[0] = 1; value[0] = 1.0;
Matrix.ReplaceMyValues( 2, 1, &value[0], &index[0] );
Matrix.FillComplete();
// Create the solution and right-hand side vectors.
Epetra_MultiVector RHS( Map, 1 ), LHS( Map, 1 );
LHS.PutScalar( 0.0 );
RHS.ReplaceMyValue( 0, 0, 3.0 );
RHS.ReplaceMyValue( 1, 0, 4.5 );
RHS.ReplaceMyValue( 2, 0, 1.0 );
Epetra_LinearProblem problem( &Matrix, &LHS, &RHS );
if (verbose) {
cout << "*************** PERFORMING BTF TRANSFORM ON LINEAR_PROBLEM **************" <<endl<<endl;
cout << "CrsMatrix *before* BTF transform: " << endl << endl;
cout << Matrix << endl;
cout << "MultiVector RHS *before* BTF transform: " << endl << endl;
RHS.Print( cout );
}
// Create the linear problem transform.
EpetraExt::LinearProblem_GraphTrans * LPTrans =
new EpetraExt::LinearProblem_GraphTrans(
*(dynamic_cast<EpetraExt::StructuralSameTypeTransform<Epetra_CrsGraph>*>(&BTFTrans)) );
Epetra_LinearProblem* tProblem = &((*LPTrans)( problem ));
LPTrans->fwd();
if (verbose) {
cout << "CrsMatrix *after* BTF transform: " << endl << endl;
dynamic_cast<Epetra_CrsMatrix*>(tProblem->GetMatrix())->Print( cout );
cout << "MultiVector RHS *after* BTF transform: " << endl << endl;
tProblem->GetRHS()->Print( cout );
}
if (verbose) {
cout << endl << "*************** PERFORMING REINDEXING ON LINEAR_PROBLEM **************" <<endl<<endl;
}
EpetraExt::ViewTransform<Epetra_LinearProblem> * ReIdx_LPTrans =
new EpetraExt::LinearProblem_Reindex( 0 );
Epetra_LinearProblem* tProblem2 = &((*ReIdx_LPTrans)( *tProblem ));
ReIdx_LPTrans->fwd();
if (verbose) {
cout << endl << "CrsMatrix *after* BTF transform *and* reindexing: " << endl << endl;
dynamic_cast<Epetra_CrsMatrix*>(tProblem2->GetMatrix())->Print( cout );
cout << endl <<"Column Map *before* reindexing: " << endl << endl;
cout << dynamic_cast<Epetra_CrsMatrix*>(tProblem->GetMatrix())->ColMap() << endl;
cout << "Column Map *after* reindexing: " << endl << endl;
cout << dynamic_cast<Epetra_CrsMatrix*>(tProblem2->GetMatrix())->ColMap() << endl;
}
#ifdef EPETRA_MPI
MPI_Finalize();
#endif
return returnierr;
}
示例7: main
//.........这里部分代码省略.........
<< "Inf norm of Original RHS = " << normb << endl;
Epetra_Time ReductionTimer(Comm);
Epetra_CrsSingletonFilter SingletonFilter;
Comm.Barrier();
double reduceInitTime = ReductionTimer.ElapsedTime();
SingletonFilter.Analyze(&A);
Comm.Barrier();
double reduceAnalyzeTime = ReductionTimer.ElapsedTime() - reduceInitTime;
if (SingletonFilter.SingletonsDetected())
cout << "Singletons found" << endl;
else {
cout << "Singletons not found" << endl;
exit(1);
}
SingletonFilter.ConstructReducedProblem(&FullProblem);
Comm.Barrier();
double reduceConstructTime = ReductionTimer.ElapsedTime() - reduceInitTime;
double totalReduceTime = ReductionTimer.ElapsedTime();
if (verbose)
cout << "\n\n****************************************************" << endl
<< " Reduction init time (sec) = " << reduceInitTime<< endl
<< " Reduction Analyze time (sec) = " << reduceAnalyzeTime << endl
<< " Construct Reduced Problem time (sec) = " << reduceConstructTime << endl
<< " Reduction Total time (sec) = " << totalReduceTime << endl<< endl;
Statistics(SingletonFilter);
Epetra_LinearProblem * ReducedProblem = SingletonFilter.ReducedProblem();
Epetra_CrsMatrix * Ap = dynamic_cast<Epetra_CrsMatrix *>(ReducedProblem->GetMatrix());
Epetra_Vector * bp = (*ReducedProblem->GetRHS())(0);
Epetra_Vector * xp = (*ReducedProblem->GetLHS())(0);
if (smallProblem)
cout << " Reduced Matrix = " << endl << *Ap << endl
<< " LHS before sol = " << endl << *xp << endl
<< " RHS = " << endl << *bp << endl;
// Construct ILU preconditioner
double elapsed_time, total_flops, MFLOPs;
Epetra_Time timer(Comm);
int LevelFill = 0;
if (argc > 2) LevelFill = atoi(argv[2]);
if (verbose) cout << "Using Level Fill = " << LevelFill << endl;
int Overlap = 0;
if (argc > 3) Overlap = atoi(argv[3]);
if (verbose) cout << "Using Level Overlap = " << Overlap << endl;
double Athresh = 0.0;
if (argc > 4) Athresh = atof(argv[4]);
if (verbose) cout << "Using Absolute Threshold Value of = " << Athresh << endl;
double Rthresh = 1.0;
if (argc > 5) Rthresh = atof(argv[5]);
if (verbose) cout << "Using Relative Threshold Value of = " << Rthresh << endl;
Ifpack_IlukGraph * IlukGraph = 0;
Ifpack_CrsRiluk * ILUK = 0;
if (LevelFill>-1) {
示例8: TestMultiLevelPreconditioner
int TestMultiLevelPreconditioner(char ProblemType[],
Teuchos::ParameterList & MLList,
Epetra_LinearProblem & Problem, double & TotalErrorResidual,
double & TotalErrorExactSol)
{
Epetra_MultiVector* lhs = Problem.GetLHS();
Epetra_MultiVector* rhs = Problem.GetRHS();
Epetra_RowMatrix* A = Problem.GetMatrix();
// ======================================== //
// create a rhs corresponding to lhs or 1's //
// ======================================== //
lhs->PutScalar(1.0);
A->Multiply(false,*lhs,*rhs);
lhs->PutScalar(0.0);
Epetra_Time Time(A->Comm());
Epetra_MultiVector lhs2(*lhs);
Epetra_MultiVector rhs2(*rhs);
// =================== //
// call ML and AztecOO //
// =================== //
AztecOO solver(Problem);
MLList.set("ML output", 0);
ML_set_random_seed(24601);
ML_Epetra::MultiLevelPreconditioner * MLPrec = new ML_Epetra::MultiLevelPreconditioner(*A, MLList, true);
// tell AztecOO to use this preconditioner, then solve
solver.SetPrecOperator(MLPrec);
solver.SetAztecOption(AZ_solver, AZ_gmres);
solver.SetAztecOption(AZ_output, 32);
solver.SetAztecOption(AZ_kspace, 160);
solver.Iterate(1550, 1e-12);
delete MLPrec;
// ================================= //
// call ML and AztecOO a second time //
// ================================= //
Epetra_LinearProblem Problem2(A,&lhs2,&rhs2);
AztecOO solver2(Problem2);
ML_set_random_seed(24601);
ML_Epetra::MultiLevelPreconditioner * MLPrec2 = new ML_Epetra::MultiLevelPreconditioner(*A, MLList, true);
// tell AztecOO to use this preconditioner, then solve
solver2.SetPrecOperator(MLPrec2);
solver2.SetAztecOption(AZ_solver, AZ_gmres);
solver2.SetAztecOption(AZ_output, 32);
solver2.SetAztecOption(AZ_kspace, 160);
solver2.Iterate(1550, 1e-12);
// ==================================================== //
// compute difference between the two ML solutions //
// ==================================================== //
double d = 0.0, d_tot = 0.0;
for( int i=0 ; i<lhs->Map().NumMyElements() ; ++i )
d += ((*lhs)[0][i] - lhs2[0][i]) * ((*lhs)[0][i] - lhs2[0][i]);
A->Comm().SumAll(&d,&d_tot,1);
string msg = ProblemType;
if (A->Comm().MyPID() == 0) {
cout << msg << "......Using " << A->Comm().NumProc() << " processes" << endl;
cout << msg << "......||x_1 - x_2||_2 = " << sqrt(d_tot) << endl;
cout << msg << "......Total Time = " << Time.ElapsedTime() << endl;
}
TotalErrorExactSol += sqrt(d_tot);
return( solver.NumIters() );
}
示例9: main
int main(int argc, char** argv) {
#if defined(HAVE_MPI) && defined(HAVE_EPETRA)
int p, numProcs = 1;
int localProc = 0;
//first, set up our MPI environment...
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &localProc);
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
int local_n = 600;
//Create a Epetra_LinearProblem object.
Epetra_LinearProblem* linprob = 0;
try {
linprob = create_epetra_problem(numProcs, localProc, local_n);
}
catch(std::exception& exc) {
std::cout << "linsys example: create_epetra_problem threw exception '"
<< exc.what() << "' on proc " << localProc << std::endl;
MPI_Finalize();
return(-1);
}
//We'll need a Teuchos::ParameterList object to pass to the
//Isorropia::Epetra::Partitioner class.
Teuchos::ParameterList paramlist;
// If Zoltan is available, the Zoltan package will be used for
// the partitioning operation. By default, Isorropia selects Zoltan's
// Hypergraph partitioner. If a method other than Hypergraph is
// desired, it can be specified by first creating a parameter sublist
// named "Zoltan", and then setting appropriate Zoltan parameters in
// that sublist. A sublist is created like this:
// Teuchos::ParameterList& sublist = paramlist.sublist("Zoltan");
//
// If Zoltan is not available, a simple linear partitioner will be
// used to partition such that the number of nonzeros is equal (or
// close to equal) on each processor.
Epetra_RowMatrix* rowmatrix = linprob->GetMatrix();
Teuchos::RCP<const Epetra_RowMatrix> rowmat =
Teuchos::rcp(rowmatrix, false);
//Now create the partitioner
Teuchos::RCP<Isorropia::Epetra::Partitioner> partitioner =
Teuchos::rcp(new Isorropia::Epetra::Partitioner(rowmat, paramlist));
//Next create a Redistributor object and use it to create balanced
//copies of the objects in linprob.
Isorropia::Epetra::Redistributor rd(partitioner);
Teuchos::RCP<Epetra_CrsMatrix> bal_matrix;
Teuchos::RCP<Epetra_MultiVector> bal_x;
Teuchos::RCP<Epetra_MultiVector> bal_b;
//Use a try-catch block because Isorropia will throw an exception
//if it encounters an error.
if (localProc == 0) {
std::cout << " calling Isorropia::Epetra::Redistributor::redistribute..."
<< std::endl;
}
try {
bal_matrix = rd.redistribute(*linprob->GetMatrix());
bal_x = rd.redistribute(*linprob->GetLHS());
bal_b = rd.redistribute(*linprob->GetRHS());
}
catch(std::exception& exc) {
std::cout << "linsys example: Isorropia::Epetra::Redistributor threw "
<< "exception '" << exc.what() << "' on proc "
<< localProc << std::endl;
MPI_Finalize();
return(-1);
}
Epetra_LinearProblem balanced_problem(bal_matrix.get(),
bal_x.get(), bal_b.get());
// Results
double goalWeight = 1.0 / (double)numProcs;
double bal0, bal1, cutn0, cutn1, cutl0, cutl1;
Isorropia::Epetra::CostDescriber default_costs;
// Balance and cut quality before partitioning
ispatest::compute_hypergraph_metrics(*(linprob->GetMatrix()), default_costs, goalWeight,
bal0, cutn0, cutl0);
// Balance and cut quality after partitioning
//.........这里部分代码省略.........