@@ -87,9 +87,6 @@ PETScABecLap::PETScABecLap (const BoxArray& grids, const DistributionMapping& dm
8787
8888 diaginv.define (grids,dmap,ncomp,0 );
8989
90- PETSC_COMM_WORLD = comm;
91- PetscInitialize (nullptr , nullptr , nullptr , nullptr );
92-
9390 solver = std::make_unique<amrex_KSP>();
9491 A = std::make_unique<amrex_Mat>();
9592 b = std::make_unique<amrex_Vec>();
@@ -106,8 +103,6 @@ PETScABecLap::~PETScABecLap ()
106103 m_factory = nullptr ;
107104 m_bndry = nullptr ;
108105 m_maxorder = -1 ;
109-
110- PetscFinalize ();
111106}
112107
113108void
181176PETScABecLap::prepareSolver ()
182177{
183178 int num_procs, myid;
184- MPI_Comm_size (PETSC_COMM_WORLD , &num_procs);
185- MPI_Comm_rank (PETSC_COMM_WORLD , &myid);
179+ MPI_Comm_size (comm , &num_procs);
180+ MPI_Comm_rank (comm , &myid);
186181
187182 const BoxArray& ba = acoefs.boxArray ();
188183 const DistributionMapping& dm = acoefs.DistributionMap ();
@@ -341,7 +336,7 @@ PETScABecLap::prepareSolver ()
341336 Vector<PetscInt> ncells_allprocs (num_procs);
342337 MPI_Allgather (&ncells_proc, sizeof (PetscInt), MPI_CHAR,
343338 ncells_allprocs.data (), sizeof (PetscInt), MPI_CHAR,
344- PETSC_COMM_WORLD );
339+ comm );
345340 PetscInt proc_begin = 0 ;
346341 for (int i = 0 ; i < myid; ++i) {
347342 proc_begin += ncells_allprocs[i];
@@ -401,7 +396,7 @@ PETScABecLap::prepareSolver ()
401396 // estimated amount of block off diag elements
402397 PetscInt o_nz = d_nz / 2 ;
403398 if (A->a ) { MatDestroy (&A->a ); }
404- MatCreate (PETSC_COMM_WORLD , &A->a );
399+ MatCreate (comm , &A->a );
405400 MatSetType (A->a , MATMPIAIJ);
406401 MatSetSizes (A->a , ncells_proc, ncells_proc, ncells_world, ncells_world);
407402 MatMPIAIJSetPreallocation (A->a , d_nz, nullptr , o_nz, nullptr );
@@ -589,7 +584,7 @@ PETScABecLap::prepareSolver ()
589584 MatAssemblyEnd (A->a , MAT_FINAL_ASSEMBLY);
590585 // create solver
591586 if (solver->a ) { KSPDestroy (&solver->a ); }
592- KSPCreate (PETSC_COMM_WORLD , &solver->a );
587+ KSPCreate (comm , &solver->a );
593588 KSPSetOperators (solver->a , A->a , A->a );
594589
595590 // Set up preconditioner
@@ -607,7 +602,7 @@ PETScABecLap::prepareSolver ()
607602 // create b & x
608603 if (x->a ) { VecDestroy (&x->a ); }
609604 if (b->a ) { VecDestroy (&b->a ); }
610- VecCreateMPI (PETSC_COMM_WORLD , ncells_proc, ncells_world, &x->a );
605+ VecCreateMPI (comm , ncells_proc, ncells_world, &x->a );
611606 VecDuplicate (x->a , &b->a );
612607}
613608
0 commit comments