[petsc-users] SNESQN number of past states

Bikash Kanungo bikash at umich.edu
Wed Feb 14 21:15:15 CST 2018


Thanks Barry and Matthew.

@Barry: I'm following the same procedure as you've mentioned -
PetscOptionsSetValue() precede SNESSetFromOptions. Here's the snippet for
my code:

-----------------------------------------------------------------------------------------------------------

      error = SNESCreate(PETSC_COMM_WORLD,&snes);
      checkPETScError(error,
                "SNESCreate failed.");

      error = SNESSetType(snes, SNESQN);
      checkPETScError(error,
                "SNESSetType failed.");

      error = SNESQNSetType(snes, SNES_QN_LBFGS);
      checkPETScError(error,
                "SNESQNSetType failed.");

      error = SNESQNSetScaleType(snes, SNES_QN_SCALE_SHANNO);
      checkPETScError(error,
                "SNESQNSetScaleType failed.");

      error = SNESQNSetRestartType(snes, SNES_QN_RESTART_PERIODIC);
      checkPETScError(error,
                "SNESQNSetRestartType failed.");

      error = PetscOptionsSetValue("-snes_qn_m","500");
      checkPETScError(error,
                "PETScOptionsSetValue failed.");

      SNESLineSearch linesearch;
      error = SNESGetLineSearch(snes,&linesearch);
      checkPETScError(error,
                "SNESGetLineSearch failed.");

      error = SNESLineSearchSetType(linesearch,SNESLINESEARCHCP);
      checkPETScError(error,
                "SNESLineSearchSetType failed.");

      error = PetscOptionsSetValue("-snes_linesearch_max_it", "1");
      checkPETScError(error,
                "PetscOptionsSetValue failed.");

      error = SNESLineSearchView(linesearch, PETSC_VIEWER_STDOUT_WORLD);
      checkPETScError(error,
                "SNESLineSearchView failed.");

      error =SNESLineSearchSetMonitor(linesearch,
                                      PETSC_TRUE);
      checkPETScError(error,
                "SNESLineSearchSet Monitor failed.");

      error = SNESLineSearchSetFromOptions(linesearch);
      checkPETScError(error,
                "SNESLineSearchSetFromOptions failed.");

      SNESLineSearchReason lineSearchReason;
      error = SNESLineSearchGetReason(linesearch, &lineSearchReason);
      checkPETScError(error,
                "SNESLineSearchGetReason failed.");

      error = SNESSetFunction(snes,r,FormFunction,&petscData);
      checkPETScError(error,
                "SNESSetFunction failed.");

      //
      // Customize KSP
      //
      error = SNESGetKSP(snes,&ksp);
      checkPETScError(error,
                "SNESGetKSP failed.");

      error = KSPSetType(ksp,KSPGMRES);
      checkPETScError(error,
                "KSPSetType failed.");

      error = KSPGMRESSetRestart(ksp,300);
      checkPETScError(error,
                "KSPGMRESSetRestart failed.");

      error = KSPSetInitialGuessNonzero(ksp,PETSC_TRUE);
      checkPETScError(error,
                "KSPSetInitialGuessNonzero failed.");

      error = KSPGetPC(ksp,&pc);
      checkPETScError(error,
                "KSPGetPC failed.");

      error = PCSetType(pc,PCJACOBI);
      checkPETScError(error,
                "PCSetType failed.");

      error = PCSetReusePreconditioner(pc,PETSC_TRUE);
      checkPETScError(error,
                "PCSetReusePreconditioner failed.");

      error = KSPSetTolerances(ksp,
                PETSC_DEFAULT,
                1e-15,
                1e7,
                10000);
      checkPETScError(error,
                "KSPSetTolerances failed.");

      error = KSPSetFromOptions(ksp);
      checkPETScError(error,
                "Call to KSPSetFromOptions() failed.");

      //
      //get reason for non-convergence
      //
      KSPConvergedReason kspReason;
      error = KSPGetConvergedReason(ksp, &kspReason);
      checkPETScError(error,
                "Call to KSPGetConvergedReason() failed.");

      if(kspReason < 0)
      {
          if(debugLevel != 0)
          std::cout<<"Other kind of divergence in SNES-KSP : "<< kspReason
<<std::endl;

      }

      PetscInt lag = 1;
      error = SNESSetLagPreconditioner(snes,
                       lag);
      checkPETScError(error,
                "Call to SNESSetLagPreconditioner() failed.");

      PetscInt maxFails = 2;
      error = SNESSetMaxLinearSolveFailures(snes,maxFails);
      checkPETScError(error,
                "Call to SNESSetMaxLinearSolveFailures() failed.");

      PetscReal abstol = 1e-13; // absolute convergence tolerance
      PetscInt  maxit  = 100000;
      error = SNESSetTolerances(snes,
                abstol,
                PETSC_DEFAULT,
                PETSC_DEFAULT,
                maxit,
                maxit);
      checkPETScError(error,
                "SNESSetTolerances failed.");

      error = SNESView(snes,
                PETSC_VIEWER_STDOUT_WORLD);
      checkPETScError(error,
                "Call to SNESView() failed.");

      error = SNESMonitorSet(snes,SNESMonitorDefault,PETSC_NULL,PETSC_NULL);
      checkPETScError(error,
                "Call to SNESMonitorSet() failed.");

      error = SNESSetFromOptions(snes);
      checkPETScError(error,
                "Call to SNESSetFromOptions() failed.");


      //
      // Solve the system
      //
      error = SNESSolve(snes,PETSC_NULL,x);
      checkPETScError(error,
                "Call to SNESSolve() failed.");

      SNESConvergedReason reason;
      error = SNESGetConvergedReason(snes,&reason);
      checkPETScError(error,
                "Call to SNESGetConvergedReason() failed.");

------------------------------------------------------------------------------------------------------------------------------------

Also, I didn't find any SNESQN examples in my snes/examples folder (using
petsc-3.6.3).
Moreover, the Powell descent condition seems to be only declared and then
assigned a value through the PetscOptionsReal call. Beyond that I didn't
find any other mention of it. I was grepping for powell_downhill variable.
(Note: powell_downhill features in 3.6.3 and not in 3.7 version).

Thanks,
Bikash


On Wed, Feb 14, 2018 at 7:02 PM, Matthew Knepley <knepley at gmail.com> wrote:

> On Wed, Feb 14, 2018 at 6:43 PM, Smith, Barry F. <bsmith at mcs.anl.gov>
> wrote:
>
>>
>>   Hmm,
>>
>> 1) make sure you call PetscOptionsSetValue() before you call to
>> SNESSetFromOptions()
>>
>> 2) make sure you call SNESSetFromOptions()
>>
>> 3) did you add a prefix to the SNES object? If so make sure you include
>> it in the PetscOptionsSetValue() call.
>>
>>   I can't see a reason why it won't work. Does it work with the PETSc
>> examples for you or not?
>>
>>    Regarding the Powell descent option, I'm afraid you'll need to examine
>> the code for exact details. src/snes/impls/qn/qn.c
>
>
> Here is the description
>
>   https://bitbucket.org/petsc/petsc/src/939b553f045c5ba32242d0d49e80e4
> 934ed3bf76/src/snes/impls/qn/qn.c?at=master&fileviewer=
> file-view-default#qn.c-451
>
>    Thanks,
>
>      Matt
>
>
>>
>>   Barry
>>
>>
>> > On Feb 14, 2018, at 5:25 PM, Bikash Kanungo <bikash at umich.edu> wrote:
>> >
>> > Hi,
>> >
>> > I'm using the L-BFGS QN solver. In order to set the number of past
>> states (also the restart size if I use Periodic restart), to say 50, I'm
>> using PetscOptionsSetValue("-snes_qn_m", "50"). However while running,
>> it still shows "Stored subspace size: 10", i.e., the default value of 10 is
>> not overwritten.
>> >
>> > Additionally, I would like to know more about the the
>> -snes_qn_powell_descent option. For Powell restart, one uses a gamma
>> parameter which I believe is defined by the -snes_qn_powell_gamma option.
>> What exactly does the descent condition do? It would be useful if there are
>> good references to it.
>> >
>> > Thanks,
>> > Biksah
>> >
>> > --
>> > Bikash S. Kanungo
>> > PhD Student
>> > Computational Materials Physics Group
>> > Mechanical Engineering
>> > University of Michigan
>> >
>>
>>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/ <http://www.caam.rice.edu/~mk51/>
>



-- 
Bikash S. Kanungo
PhD Student
Computational Materials Physics Group
Mechanical Engineering
University of Michigan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180214/449a7e3d/attachment-0001.html>


More information about the petsc-users mailing list