Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

petsc-3.5: SNES_VI_(N)INF --> PETSC_(N)INFINITY #206

Merged
merged 2 commits into from

5 participants

@karpeev
Collaborator

Upcoming petsc-3.5 API change.
Needed to compile libmesh against a recent petsc/master.

@jwpeterson
Owner

Use the new PETSC_RELEASE_LESS_THAN macro.

@moosebuild
Owner

A build job for 6a8aa9c from recipe libmesh is waiting for a developer to activate it here: https://www.moosebuild.com/view_job/560

@moosebuild
Owner

Results of testing 6a8aa9c using libmesh recipe:

Failed on: linux

View the results here: https://www.moosebuild.com/view_job/560

@friedmud
Owner

Those compile failures look real to me... Can you tell what's wrong @karpeev ?

@jwpeterson
Owner
@permcody
Collaborator
@jwpeterson
Owner

I don't know why there is a conflict either but I can fixup the recipe so
that it errors out properly if there is a merge conflict before testing.

Thanks Cody! I think Dmitry and I determined that his conflicts are due to whitespace changes I made on the master branch, and the fact that he has this long-lived feature branch that is not periodically rebased/merged from master...

@moosebuild
Owner

A build job for 7ada847 from recipe libmesh is waiting for a developer to activate it here: https://www.moosebuild.com/view_job/1161

@moosebuild
Owner

Results of testing 7ada847 using libmesh recipe:

Passed on: linux

View the results here: https://www.moosebuild.com/view_job/1161

@jwpeterson
Owner
@friedmud friedmud commented on the diff
src/numerics/petsc_preconditioner.C
((5 lines not shown))
int ierr = PCSetOperators(_pc,_mat,_mat,SAME_NONZERO_PATTERN);
+#else
+ int ierr = PCSetOperators(_pc,_mat,_mat);
@friedmud Owner

Why don't we pass SAME_NONZERO_PATTERN anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jwpeterson

No extra indentation level within namespaces.

Collaborator

Okay, I'll push an amended commit.

@jwpeterson
Owner

@karpeev can you comment on what is happening to the SAME_NONZERO_PATTERN flag that used to be passed to PCSetOperators and KSPSetOperators? Is that flag somehow taken from one of the Mat objects in PETSc dev/3.5? If so, where is that flag actually being set in libmesh now?

@karpeev
Collaborator

There is no longer a need for the user to set the nonzero pattern flag: Mat and KSP/PC objects keep track of the nonzero state of the underlying matrix (Mat changes its nonzero state every time the nonzero pattern actually changes). If the Mat's and KSP's states diverge, the PC is rebuilt.

@friedmud friedmud merged commit 17ab1d6 into libMesh:master

1 check passed

Details default Successfully passed all tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2014
  1. @karpeev
  2. @karpeev

    petsc-3.5: dropping explicit MatStructure argument and Mat indirectio…

    karpeev authored
    …n from KSP/PCSetOperators() and friends.
This page is out of date. Refresh to see the latest.
View
24 include/solvers/petsc_nonlinear_solver.h
@@ -38,14 +38,18 @@ EXTERN_C_FOR_PETSC_END
namespace libMesh
{
-// Allow users access to these functions in case they want to reuse them. Note that users shouldn't
-// need access to these most of the time as they are used internally by this object.
-extern "C"
-{
- PetscErrorCode __libmesh_petsc_snes_monitor (SNES, PetscInt its, PetscReal fnorm, void *);
- PetscErrorCode __libmesh_petsc_snes_residual (SNES, Vec x, Vec r, void *ctx);
- PetscErrorCode __libmesh_petsc_snes_jacobian (SNES, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx);
-}
+ // Allow users access to these functions in case they want to reuse them. Note that users shouldn't
+ // need access to these most of the time as they are used internally by this object.
+ extern "C"
+ {
+ PetscErrorCode __libmesh_petsc_snes_monitor (SNES, PetscInt its, PetscReal fnorm, void *);
+ PetscErrorCode __libmesh_petsc_snes_residual (SNES, Vec x, Vec r, void *ctx);
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
+ PetscErrorCode __libmesh_petsc_snes_jacobian (SNES, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx);
+#else
+ PetscErrorCode __libmesh_petsc_snes_jacobian (SNES, Vec x, Mat jac, Mat pc, void *ctx);
+#endif
+ }
/**
* This class provides an interface to PETSc
@@ -189,7 +193,11 @@ class PetscNonlinearSolver : public NonlinearSolver<T>
#endif
friend PetscErrorCode __libmesh_petsc_snes_residual (SNES snes, Vec x, Vec r, void *ctx);
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
friend PetscErrorCode __libmesh_petsc_snes_jacobian (SNES snes, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx);
+#else
+ friend PetscErrorCode __libmesh_petsc_snes_jacobian (SNES snes, Vec x, Mat jac, Mat pc, void *ctx);
+#endif
};
View
4 src/numerics/petsc_preconditioner.C
@@ -83,7 +83,11 @@ void PetscPreconditioner<T>::init ()
_mat = pmatrix->mat();
}
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
int ierr = PCSetOperators(_pc,_mat,_mat,SAME_NONZERO_PATTERN);
+#else
+ int ierr = PCSetOperators(_pc,_mat,_mat);
@friedmud Owner

Why don't we pass SAME_NONZERO_PATTERN anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+#endif
LIBMESH_CHKERRABORT(ierr);
// Set the PCType. Note: this used to be done *before* the call to
View
43 src/solvers/petsc_diff_solver.C
@@ -134,14 +134,20 @@ extern "C"
}
- PetscErrorCode
- __libmesh_petsc_diff_solver_jacobian (SNES, Vec x, Mat *libmesh_dbg_var(j), Mat *pc,
- MatStructure *msflag, void *ctx)
- {
- libmesh_assert(x);
- libmesh_assert(j);
- // libmesh_assert_equal_to (pc, j); // We don't use separate preconditioners yet
- libmesh_assert(ctx);
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
+PetscErrorCode
+__libmesh_petsc_diff_solver_jacobian (SNES, Vec x, Mat *libmesh_dbg_var(j), Mat *pc,
+ MatStructure *msflag, void *ctx)
+#else
+PetscErrorCode
+__libmesh_petsc_diff_solver_jacobian (SNES, Vec x, Mat libmesh_dbg_var(j), Mat pc,
+ void *ctx)
+#endif
+{
+ libmesh_assert(x);
+ libmesh_assert(j);
+// libmesh_assert_equal_to (pc, j); // We don't use separate preconditioners yet
+ libmesh_assert(ctx);
PetscDiffSolver& solver =
*(static_cast<PetscDiffSolver*> (ctx));
@@ -154,9 +160,13 @@ extern "C"
*libmesh_cast_ptr<PetscVector<Number>*>(sys.solution.get());
PetscVector<Number> X_input(x, sys.comm());
- PetscMatrix<Number> J_input(*pc, sys.comm());
- PetscMatrix<Number>& J_system =
- *libmesh_cast_ptr<PetscMatrix<Number>*>(sys.matrix);
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
+ PetscMatrix<Number> J_input(*pc, sys.comm());
+#else
+ PetscMatrix<Number> J_input(pc, sys.comm());
+#endif
+ PetscMatrix<Number>& J_system =
+ *libmesh_cast_ptr<PetscMatrix<Number>*>(sys.matrix);
// DiffSystem assembles from the solution and into the jacobian, so
// swap those with our input vectors before assembling. They'll
@@ -179,11 +189,12 @@ extern "C"
X_input.swap(X_system);
J_input.swap(J_system);
- *msflag = SAME_NONZERO_PATTERN;
-
- // No errors, we hope
- return 0;
- }
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
+ *msflag = SAME_NONZERO_PATTERN;
+#endif
+ // No errors, we hope
+ return 0;
+}
} // extern "C"
View
140 src/solvers/petsc_linear_solver.C
@@ -340,7 +340,11 @@ void PetscLinearSolver<T>::init ( PetscMatrix<T>* matrix,
LIBMESH_CHKERRABORT(ierr);
// Set operators. The input matrix works as the preconditioning matrix
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, matrix->mat(), matrix->mat(),DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, matrix->mat(), matrix->mat());
+#endif
LIBMESH_CHKERRABORT(ierr);
// Set user-specified solver and preconditioner types
@@ -673,16 +677,19 @@ PetscLinearSolver<T>::solve (SparseMatrix<T>& matrix_in,
ierr = MatMultAdd(submat1,subvec1,subrhs,subrhs);
LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshVecScatterDestroy(&scatter1);
- LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshVecDestroy(&subvec1);
- LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshMatDestroy(&submat1);
- LIBMESH_CHKERRABORT(ierr);
- }
-
+ ierr = LibMeshVecScatterDestroy(&scatter1);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = LibMeshVecDestroy(&subvec1);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = LibMeshMatDestroy(&submat1);
+ LIBMESH_CHKERRABORT(ierr);
+ }
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, submat, subprecond,
- this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+ this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, submat, subprecond);
+#endif
LIBMESH_CHKERRABORT(ierr);
if(this->_preconditioner)
@@ -695,8 +702,12 @@ PetscLinearSolver<T>::solve (SparseMatrix<T>& matrix_in,
}
else
{
+ #if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, matrix->mat(), precond->mat(),
- this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+ this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, matrix->mat(), precond->mat());
+#endif
LIBMESH_CHKERRABORT(ierr);
if(this->_preconditioner)
@@ -1011,16 +1022,19 @@ PetscLinearSolver<T>::adjoint_solve (SparseMatrix<T>& matrix_in,
ierr = MatMultAdd(submat1,subvec1,subrhs,subrhs);
LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshVecScatterDestroy(&scatter1);
- LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshVecDestroy(&subvec1);
- LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshMatDestroy(&submat1);
- LIBMESH_CHKERRABORT(ierr);
- }
-
+ ierr = LibMeshVecScatterDestroy(&scatter1);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = LibMeshVecDestroy(&subvec1);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = LibMeshMatDestroy(&submat1);
+ LIBMESH_CHKERRABORT(ierr);
+ }
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, submat, subprecond,
- this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+ this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, submat, subprecond);
+#endif
LIBMESH_CHKERRABORT(ierr);
if(this->_preconditioner)
@@ -1033,8 +1047,12 @@ PetscLinearSolver<T>::adjoint_solve (SparseMatrix<T>& matrix_in,
}
else
{
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, matrix->mat(), precond->mat(),
- this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+ this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, matrix->mat(), precond->mat());
+#endif
LIBMESH_CHKERRABORT(ierr);
if(this->_preconditioner)
@@ -1285,44 +1303,50 @@ PetscLinearSolver<T>::solve (const ShellMatrix<T>& shell_matrix,
LIBMESH_CHKERRABORT(ierr);
#endif
- // The following lines would be correct, but don't work
- // correctly in PETSc up to 3.1.0-p5. See discussion in
- // petsc-users of Nov 9, 2010.
- //
- // ierr = MatMultAdd(submat1,subvec1,subrhs,subrhs);
- // LIBMESH_CHKERRABORT(ierr);
- //
- // We workaround by using a temporary vector. Note that the
- // fix in PETsc 3.1.0-p6 uses a temporary vector internally,
- // so this is no effective performance loss.
- Vec subvec2 = NULL;
- ierr = VecCreate(this->comm().get(),&subvec2);
- LIBMESH_CHKERRABORT(ierr);
- ierr = VecSetSizes(subvec2,is_local_size,PETSC_DECIDE);
- LIBMESH_CHKERRABORT(ierr);
- ierr = VecSetFromOptions(subvec2);
- LIBMESH_CHKERRABORT(ierr);
- ierr = MatMult(submat1,subvec1,subvec2);
- LIBMESH_CHKERRABORT(ierr);
- ierr = VecAXPY(subrhs,1.0,subvec2);
- LIBMESH_CHKERRABORT(ierr);
-
- ierr = LibMeshVecScatterDestroy(&scatter1);
- LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshVecDestroy(&subvec1);
- LIBMESH_CHKERRABORT(ierr);
- ierr = LibMeshMatDestroy(&submat1);
- LIBMESH_CHKERRABORT(ierr);
- }
-
+ // The following lines would be correct, but don't work
+ // correctly in PETSc up to 3.1.0-p5. See discussion in
+ // petsc-users of Nov 9, 2010.
+ //
+ // ierr = MatMultAdd(submat1,subvec1,subrhs,subrhs);
+ // LIBMESH_CHKERRABORT(ierr);
+ //
+ // We workaround by using a temporary vector. Note that the
+ // fix in PETsc 3.1.0-p6 uses a temporary vector internally,
+ // so this is no effective performance loss.
+ Vec subvec2 = NULL;
+ ierr = VecCreate(this->comm().get(),&subvec2);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = VecSetSizes(subvec2,is_local_size,PETSC_DECIDE);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = VecSetFromOptions(subvec2);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = MatMult(submat1,subvec1,subvec2);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = VecAXPY(subrhs,1.0,subvec2);
+
+ ierr = LibMeshVecScatterDestroy(&scatter1);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = LibMeshVecDestroy(&subvec1);
+ LIBMESH_CHKERRABORT(ierr);
+ ierr = LibMeshMatDestroy(&submat1);
+ LIBMESH_CHKERRABORT(ierr);
+ }
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, submat, submat,
- DIFFERENT_NONZERO_PATTERN);
+ DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, submat, submat);
+#endif
LIBMESH_CHKERRABORT(ierr);
}
else
{
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, mat, mat,
- DIFFERENT_NONZERO_PATTERN);
+ DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, mat, mat);
+#endif
LIBMESH_CHKERRABORT(ierr);
}
@@ -1599,8 +1623,12 @@ PetscLinearSolver<T>::solve (const ShellMatrix<T>& shell_matrix,
LIBMESH_CHKERRABORT(ierr);
}
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, submat, subprecond,
- DIFFERENT_NONZERO_PATTERN);
+ DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, submat, subprecond);
+#endif
LIBMESH_CHKERRABORT(ierr);
if(this->_preconditioner)
@@ -1613,8 +1641,12 @@ PetscLinearSolver<T>::solve (const ShellMatrix<T>& shell_matrix,
}
else
{
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = KSPSetOperators(_ksp, mat, const_cast<PetscMatrix<T>*>(precond)->mat(),
- DIFFERENT_NONZERO_PATTERN);
+ DIFFERENT_NONZERO_PATTERN);
+#else
+ ierr = KSPSetOperators(_ksp, mat, const_cast<PetscMatrix<T>*>(precond)->mat());
+#endif
LIBMESH_CHKERRABORT(ierr);
if(this->_preconditioner)
View
15 src/solvers/petsc_nonlinear_solver.C
@@ -153,8 +153,13 @@ extern "C"
//---------------------------------------------------------------
// this function is called by PETSc to evaluate the Jacobian at X
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
PetscErrorCode
__libmesh_petsc_snes_jacobian (SNES snes, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx)
+#else
+ PetscErrorCode
+ __libmesh_petsc_snes_jacobian (SNES snes, Vec x, Mat jac, Mat pc, void *ctx)
+#endif
{
START_LOG("jacobian()", "PetscNonlinearSolver");
@@ -176,9 +181,13 @@ extern "C"
}
NonlinearImplicitSystem &sys = solver->system();
-
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
PetscMatrix<Number> PC(*pc, sys.comm());
PetscMatrix<Number> Jac(*jac, sys.comm());
+#else
+ PetscMatrix<Number> PC(pc, sys.comm());
+ PetscMatrix<Number> Jac(jac, sys.comm());
+#endif
PetscVector<Number>& X_sys = *libmesh_cast_ptr<PetscVector<Number>*>(sys.solution.get());
PetscMatrix<Number>& Jac_sys = *libmesh_cast_ptr<PetscMatrix<Number>*>(sys.matrix);
PetscVector<Number> X_global(x, sys.comm());
@@ -225,9 +234,9 @@ extern "C"
PC.close();
Jac.close();
X_global.close();
-
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
*msflag = SAME_NONZERO_PATTERN;
-
+#endif
STOP_LOG("jacobian()", "PetscNonlinearSolver");
return ierr;
View
25 src/solvers/petscdmlibmesh.C
@@ -794,7 +794,11 @@ static PetscErrorCode SNESFunction_DMlibMesh(SNES, Vec x, Vec r, void *ctx)
#undef __FUNCT__
#define __FUNCT__ "DMlibMeshJacobian"
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
static PetscErrorCode DMlibMeshJacobian(DM dm, Vec x, Mat jac, Mat pc, MatStructure *msflag)
+#else
+static PetscErrorCode DMlibMeshJacobian(DM dm, Vec x, Mat jac, Mat pc)
+#endif
{
PetscErrorCode ierr;
PetscFunctionBegin;
@@ -856,20 +860,29 @@ static PetscErrorCode DMlibMeshJacobian(DM dm, Vec x, Mat jac, Mat pc, MatStruct
the_pc.close();
Jac.close();
X_global.close();
-
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
*msflag = SAME_NONZERO_PATTERN;
+#endif
PetscFunctionReturn(0);
}
#if !PETSC_RELEASE_LESS_THAN(3,3,1)
#undef __FUNCT__
#define __FUNCT__ "SNESJacobian_DMlibMesh"
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
static PetscErrorCode SNESJacobian_DMlibMesh(SNES,Vec x,Mat *jac,Mat *pc, MatStructure* flag, void* ctx)
+#else
+static PetscErrorCode SNESJacobian_DMlibMesh(SNES,Vec x,Mat jac,Mat pc, void* ctx)
+#endif
{
DM dm = (DM)ctx;
PetscErrorCode ierr;
PetscFunctionBegin;
+#if PETSC_RELEASE_LESS_THAN(3,5,0)
ierr = DMlibMeshJacobian(dm,x,*jac,*pc,flag); CHKERRQ(ierr);
+#else
+ ierr = DMlibMeshJacobian(dm,x,jac,pc); CHKERRQ(ierr);
+#endif
PetscFunctionReturn(0);
}
#endif
@@ -885,9 +898,13 @@ static PetscErrorCode DMVariableBounds_libMesh(DM dm, Vec xl, Vec xu)
PetscVector<Number> XL(xl, sys.comm());
PetscVector<Number> XU(xu, sys.comm());
PetscFunctionBegin;
-
- ierr = VecSet(xl, SNES_VI_NINF); CHKERRQ(ierr);
- ierr = VecSet(xu, SNES_VI_INF); CHKERRQ(ierr);
+#if PETSC_VERSION_LESS_THAN(3,5,0) && PETSC_VERSION_RELEASE
+ ierr = VecSet(xl, SNES_VI_NINF);CHKERRQ(ierr);
+ ierr = VecSet(xu, SNES_VI_INF);CHKERRQ(ierr);
+#else
+ ierr = VecSet(xl, PETSC_NINFINITY);CHKERRQ(ierr);
+ ierr = VecSet(xu, PETSC_INFINITY);CHKERRQ(ierr);
+#endif
if (sys.nonlinear_solver->bounds != NULL)
sys.nonlinear_solver->bounds(XL,XU,sys);
else if (sys.nonlinear_solver->bounds_object != NULL)
Something went wrong with that request. Please try again.