Skip to content

Commit 20f0991

Browse files
authored
Merge pull request #3501 from roystgnr/more_parallel_only
Add parallel_only calls to PetscNonlinearSolver
2 parents 6b1f19f + 3854513 commit 20f0991

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/solvers/petsc_nonlinear_solver.C

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ libmesh_petsc_snes_residual_helper (SNES snes, Vec x, void * ctx)
6464
PetscNonlinearSolver<Number> * solver =
6565
static_cast<PetscNonlinearSolver<Number> *> (ctx);
6666

67+
libmesh_parallel_only(solver->comm());
68+
6769
// Get the current iteration number from the snes object,
6870
// store it in the PetscNonlinearSolver object for possible use
6971
// by the user's residual function.
@@ -171,6 +173,8 @@ extern "C"
171173
{
172174
ResidualContext rc = libmesh_petsc_snes_residual_helper(snes, x, ctx);
173175

176+
libmesh_parallel_only(rc.sys.comm());
177+
174178
libmesh_assert(r);
175179
PetscVector<Number> R(r, rc.sys.comm());
176180

@@ -247,6 +251,8 @@ extern "C"
247251
{
248252
ResidualContext rc = libmesh_petsc_snes_residual_helper(snes, x, ctx);
249253

254+
libmesh_parallel_only(rc.sys.comm());
255+
250256
libmesh_assert(r);
251257
PetscVector<Number> R(r, rc.sys.comm());
252258

@@ -296,6 +302,8 @@ extern "C"
296302
{
297303
ResidualContext rc = libmesh_petsc_snes_residual_helper(snes, x, ctx);
298304

305+
libmesh_parallel_only(rc.sys.comm());
306+
299307
libmesh_assert(r);
300308
PetscVector<Number> R(r, rc.sys.comm());
301309

@@ -438,6 +446,8 @@ extern "C"
438446
PetscNonlinearSolver<Number> * solver =
439447
static_cast<PetscNonlinearSolver<Number> *> (ctx);
440448

449+
libmesh_parallel_only(solver->comm());
450+
441451
// Get the current iteration number from the snes object,
442452
// store it in the PetscNonlinearSolver object for possible use
443453
// by the user's Jacobian function.
@@ -520,7 +530,7 @@ extern "C"
520530

521531
// This function gets called by PETSc in place of the standard Petsc line searches
522532
// if a linesearch object is supplied to the PetscNonlinearSolver class. It wraps
523-
// the lineserach algorithm implemented on the linesearch object.
533+
// the linesearch algorithm implemented on the linesearch object.
524534
// * "linesearch" is an object that can be used to access the non-linear and linear solution
525535
// vectors as well as the residual and SNES object
526536
// * "ctx" is the PetscNonlinearSolver context
@@ -530,6 +540,8 @@ extern "C"
530540
PetscNonlinearSolver<Number> * solver =
531541
static_cast<PetscNonlinearSolver<Number> *> (ctx);
532542

543+
libmesh_parallel_only(solver->comm());
544+
533545
solver->linesearch_object->linesearch(linesearch);
534546
return 0;
535547
}
@@ -570,6 +582,8 @@ extern "C"
570582
PetscNonlinearSolver<Number> * solver =
571583
static_cast<PetscNonlinearSolver<Number> *> (context);
572584

585+
libmesh_parallel_only(solver->comm());
586+
573587
// If the user has provided both postcheck function pointer and
574588
// object, this is ambiguous, so throw an error.
575589
libmesh_error_msg_if(solver->postcheck && solver->postcheck_object,
@@ -687,6 +701,8 @@ void PetscNonlinearSolver<T>::clear ()
687701
template <typename T>
688702
void PetscNonlinearSolver<T>::init (const char * name)
689703
{
704+
parallel_object_only();
705+
690706
// Initialize the data structures if not done so already.
691707
if (!this->initialized())
692708
{
@@ -787,6 +803,8 @@ PetscNonlinearSolver<T>::build_mat_null_space(NonlinearImplicitSystem::ComputeVe
787803
void (*computeSubspace)(std::vector<NumericVector<Number> *> &, sys_type &),
788804
MatNullSpace * msp)
789805
{
806+
parallel_object_only();
807+
790808
PetscErrorCode ierr;
791809
std::vector<NumericVector<Number> *> sp;
792810
if (computeSubspaceObject)
@@ -852,6 +870,8 @@ PetscNonlinearSolver<T>::solve (SparseMatrix<T> & pre_in, // System Preconditi
852870
const double, // Stopping tolerance
853871
const unsigned int)
854872
{
873+
parallel_object_only();
874+
855875
LOG_SCOPE("solve()", "PetscNonlinearSolver");
856876
this->init ();
857877

0 commit comments

Comments
 (0)