Re: [petsc-users] SNESQN number of past states

2018-02-15 Thread Bikash Kanungo
Thanks again Barry. I figured it out. My SNESView was called before
SNESSetFromOptions and hence was showing the default value.

Regards,
Bikash

On Wed, Feb 14, 2018 at 11:28 PM, Smith, Barry F. 
wrote:

>
>   I stuck the line
>
>   PetscOptionsSetValue(NULL,"-snes_qn_m", "50");
>
> in src/snes/examples/tutorials/ex19.c
>
> and called it with
>
> -da_refine 2 -snes_monitor -snes_type qn -snes_view
>
> and the results showed
>
> Stored subspace size: 50
>
> so I am afraid it is something unique to exactly your code that is causing
> it to be not used. If you can send us a complete code that reproduces the
> problem we can track it down and fix it but without a reproducing code we
> can't do anything to resolve the problem.
>
>Barry
>
>
> > On Feb 14, 2018, at 9:15 PM, Bikash Kanungo  wrote:
> >
> > 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,
> > 1);
> >   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.

Re: [petsc-users] SNESQN number of past states

2018-02-14 Thread Smith, Barry F.

  I stuck the line

  PetscOptionsSetValue(NULL,"-snes_qn_m", "50");

in src/snes/examples/tutorials/ex19.c 

and called it with 

-da_refine 2 -snes_monitor -snes_type qn -snes_view

and the results showed

Stored subspace size: 50

so I am afraid it is something unique to exactly your code that is causing it 
to be not used. If you can send us a complete code that reproduces the problem 
we can track it down and fix it but without a reproducing code we can't do 
anything to resolve the problem.

   Barry


> On Feb 14, 2018, at 9:15 PM, Bikash Kanungo  wrote:
> 
> 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,
> 1); 
>   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 
> < 
>   } 
> 
>   PetscInt lag = 1;
>   error = SNESSetLagPreconditioner(snes,
>lag);
>   checkPETScError(error,
> "Ca

Re: [petsc-users] SNESQN number of past states

2018-02-14 Thread Bikash Kanungo
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,
1);
  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
< wrote:

> On Wed, Feb 14, 2018 at 6:43 PM, Smith, Barry F. 
> 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  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"). Ho

Re: [petsc-users] SNESQN number of past states

2018-02-14 Thread Matthew Knepley
On Wed, Feb 14, 2018 at 6:43 PM, Smith, Barry F.  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/939b553f045c5ba32242d0d49e80e4934ed3bf76/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  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/ 


Re: [petsc-users] SNESQN number of past states

2018-02-14 Thread Smith, Barry F.

  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

  Barry


> On Feb 14, 2018, at 5:25 PM, Bikash Kanungo  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
> 



[petsc-users] SNESQN number of past states

2018-02-14 Thread Bikash Kanungo
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