本文整理汇总了C++中Epetra_MpiComm类的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_MpiComm类的具体用法?C++ Epetra_MpiComm怎么用?C++ Epetra_MpiComm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Epetra_MpiComm类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//=============================================================================
Epetra_MpiComm::Epetra_MpiComm(const Epetra_MpiComm & Comm) :
Epetra_Object(Comm.Label()),
MpiCommData_(Comm.MpiCommData_)
{
MpiCommData_->IncrementReferenceCount();
}
示例2: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm (MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
Teuchos::ParameterList GaleriList;
int nx = 30;
GaleriList.set("nx", nx);
// GaleriList.set("ny", nx * Comm.NumProc());
GaleriList.set("ny", nx);
GaleriList.set("mx", 1);
GaleriList.set("my", Comm.NumProc());
GaleriList.set("alpha", .0);
GaleriList.set("diff", 1.0);
GaleriList.set("conv", 100.0);
Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("UniFlow2D", &*Map, GaleriList) );
Teuchos::RefCountPtr<Epetra_MultiVector> LHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
Teuchos::RefCountPtr<Epetra_MultiVector> RHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
LHS->PutScalar(0.0); RHS->Random();
Ifpack Factory;
int Niters = 100;
// ============================= //
// Construct IHSS preconditioner //
// ============================= //
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.Create("IHSS", &*A,0) );
Teuchos::ParameterList List;
List.set("ihss: hermetian type","ILU");
List.set("ihss: skew hermetian type","ILU");
List.set("ihss: ratio eigenvalue",100.0);
// Could set sublist values here to better control the ILU, but this isn't needed for this example.
IFPACK_CHK_ERR(Prec->SetParameters(List));
IFPACK_CHK_ERR(Prec->Compute());
// ============================= //
// Create solver Object //
// ============================= //
AztecOO solver;
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_gmres);
solver.SetPrecOperator(&*Prec);
solver.SetAztecOption(AZ_output, 1);
solver.Iterate(Niters, 1e-8);
// ============================= //
// Construct SORa preconditioner //
// ============================= //
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec2 = Teuchos::rcp( Factory.Create("SORa", &*A,0) );
Teuchos::ParameterList List2;
List2.set("sora: sweeps",1);
// Could set sublist values here to better control the ILU, but this isn't needed for this example.
IFPACK_CHK_ERR(Prec2->SetParameters(List2));
IFPACK_CHK_ERR(Prec2->Compute());
// ============================= //
// Create solver Object //
// ============================= //
AztecOO solver2;
LHS->PutScalar(0.0);
solver2.SetUserMatrix(&*A);
solver2.SetLHS(&*LHS);
solver2.SetRHS(&*RHS);
solver2.SetAztecOption(AZ_solver,AZ_gmres);
solver2.SetPrecOperator(&*Prec2);
solver2.SetAztecOption(AZ_output, 1);
solver2.Iterate(Niters, 1e-8);
#ifdef HAVE_MPI
MPI_Finalize() ;
#endif
return(EXIT_SUCCESS);
}
示例3: main
int main(int argc, char *argv[]) {
#ifdef EPETRA_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm (MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int MyPID = Comm.MyPID();
bool verbose = true;
if (MyPID==0) verbose = true;
if (verbose)
cout << EpetraExt::EpetraExt_Version() << endl << endl;
cout << Comm << endl;
if(argc < 2 && verbose) {
cerr << "Usage: " << argv[0]
<< " HB_filename" << endl;
return(1);
}
// Uncomment the next three lines to debug in mpi mode
//int tmp;
//if (MyPID==0) cin >> tmp;
//Comm.Barrier();
Epetra_Map * readMap;
Epetra_CrsMatrix * readA;
Epetra_Vector * readx;
Epetra_Vector * readb;
Epetra_Vector * readxexact;
// Call routine to read in HB problem
Trilinos_Util_ReadHb2Epetra(argv[1], Comm, readMap, readA, readx, readb, readxexact);
// Create uniform distributed map
Epetra_Map map(readMap->NumGlobalElements(), 0, Comm);
// Create Exporter to distribute read-in matrix and vectors
Epetra_Export exporter(*readMap, map);
Epetra_CrsMatrix A(Copy, map, 0);
Epetra_Vector x(map);
Epetra_Vector b(map);
Epetra_Vector xexact(map);
Epetra_Time FillTimer(Comm);
x.Export(*readx, exporter, Add);
b.Export(*readb, exporter, Add);
xexact.Export(*readxexact, exporter, Add);
Comm.Barrier();
double vectorRedistributeTime = FillTimer.ElapsedTime();
A.Export(*readA, exporter, Add);
Comm.Barrier();
double matrixRedistributeTime = FillTimer.ElapsedTime() - vectorRedistributeTime;
assert(A.FillComplete()==0);
Comm.Barrier();
double fillCompleteTime = FillTimer.ElapsedTime() - matrixRedistributeTime;
if (Comm.MyPID()==0) {
cout << "\n\n****************************************************" << endl;
cout << "\n Vector redistribute time (sec) = " << vectorRedistributeTime<< endl;
cout << " Matrix redistribute time (sec) = " << matrixRedistributeTime << endl;
cout << " Transform to Local time (sec) = " << fillCompleteTime << endl<< endl;
}
Epetra_Vector tmp1(*readMap);
Epetra_Vector tmp2(map);
readA->Multiply(false, *readxexact, tmp1);
A.Multiply(false, xexact, tmp2);
double residual;
tmp1.Norm2(&residual);
if (verbose) cout << "Norm of Ax from file = " << residual << endl;
tmp2.Norm2(&residual);
if (verbose) cout << "Norm of Ax after redistribution = " << residual << endl << endl << endl;
//cout << "A from file = " << *readA << endl << endl << endl;
//cout << "A after dist = " << A << endl << endl << endl;
delete readA;
delete readx;
delete readb;
delete readxexact;
delete readMap;
Comm.Barrier();
EpetraExt::RowMatrixToMatrixMarketFile("test.mm", A, "test matrix", "This is a test matrix");
#ifdef EPETRA_MPI
MPI_Finalize() ;
#endif
return 0 ;
}
示例4: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm (MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int MyPID = Comm.MyPID();
bool verbose = false;
if (MyPID==0) verbose = true;
Teuchos::ParameterList GaleriList;
int nx = 30;
GaleriList.set("nx", nx);
GaleriList.set("ny", nx * Comm.NumProc());
GaleriList.set("mx", 1);
GaleriList.set("my", Comm.NumProc());
Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
Teuchos::RefCountPtr<Epetra_MultiVector> LHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
Teuchos::RefCountPtr<Epetra_MultiVector> RHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
LHS->PutScalar(0.0); RHS->Random();
// ============================ //
// Construct ILU preconditioner //
// ---------------------------- //
// I wanna test funky values to be sure that they have the same
// influence on the algorithms, both old and new
int LevelFill = 2;
double DropTol = 0.3333;
double Athresh = 0.0123;
double Rthresh = 0.9876;
double Relax = 0.1;
int Overlap = 2;
Teuchos::RefCountPtr<Ifpack_IlukGraph> Graph;
Teuchos::RefCountPtr<Ifpack_CrsRiluk> RILU;
Graph = Teuchos::rcp( new Ifpack_IlukGraph(A->Graph(), LevelFill, Overlap) );
int ierr;
ierr = Graph->ConstructFilledGraph();
IFPACK_CHK_ERR(ierr);
RILU = Teuchos::rcp( new Ifpack_CrsRiluk(*Graph) );
RILU->SetAbsoluteThreshold(Athresh);
RILU->SetRelativeThreshold(Rthresh);
RILU->SetRelaxValue(Relax);
int initerr = RILU->InitValues(*A);
if (initerr!=0) cout << Comm << "*ERR* InitValues = " << initerr;
RILU->Factor();
// Define label for printing out during the solve phase
string label = "Ifpack_CrsRiluk Preconditioner: LevelFill = " + toString(LevelFill) +
" Overlap = " + toString(Overlap) +
" Athresh = " + toString(Athresh) +
" Rthresh = " + toString(Rthresh);
// Here we create an AztecOO object
LHS->PutScalar(0.0);
int Niters = 1200;
AztecOO solver;
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_gmres);
solver.SetPrecOperator(&*RILU);
solver.SetAztecOption(AZ_output, 16);
solver.Iterate(Niters, 5.0e-5);
int OldIters = solver.NumIters();
// now rebuild the same preconditioner using RILU, we expect the same
// number of iterations
Ifpack Factory;
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.Create("ILU", &*A, Overlap) );
Teuchos::ParameterList List;
List.get("fact: level-of-fill", LevelFill);
List.get("fact: drop tolerance", DropTol);
List.get("fact: absolute threshold", Athresh);
List.get("fact: relative threshold", Rthresh);
List.get("fact: relax value", Relax);
IFPACK_CHK_ERR(Prec->SetParameters(List));
IFPACK_CHK_ERR(Prec->Compute());
// Here we create an AztecOO object
LHS->PutScalar(0.0);
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_gmres);
//.........这里部分代码省略.........