Make sure you always respond to petsc-users so the email doesn't just get 
sent to me. Someone else would have already helped you.

   Ahh, the problem is we copy the scale value out of the KSP object at the 
beginning of the routine into a local variable so it remains the same value 
even though you correctly change the value in the KSP object.

   I have changed the Richardson code in the maint and master branch so if you 
use it there the scaling will work as you desire. (Just follow the git 
instructions at http://www.mcs.anl.gov/petsc/download/index.html for obtaining 
PETSc.)





   Barry

> On Jul 28, 2016, at 9:24 AM, JC <[email protected]> wrote:
> 
> Hej,
> 
> I have tried to use kspMonitorSet to change the value of the scale in the 
> Richardson iteration, however it does not seem to take it into account when 
> actually solving the problem. Here is my monitoring routine. relaxation is an 
> array declared in my module. If I do print *, relaxation(ind), then the 
> correct value is printed. It is not passed to the KSP framework however 
> despite the call to ksprichardsonsetscale. Any idea why?
> 
> Thanks a lot,
> JC
> 
> 
>  subroutine MyKSPMonitor(solver, iter, dummy_1, dummy_2, ierr)
> 
>    !----- Inputs -----!
> 
>    KSP, intent(inout) :: solver
>    PetscInt, intent(in) :: iter
>    PetscReal, intent(in) :: dummy_1
>    PetscInt, intent(in) :: dummy_2
> 
>    !----- Output -----!
> 
>    PetscErrorCode, intent(out) :: ierr
> 
>    !----- Miscellaneous -----!
> 
>    PetscInt :: ind
>    PetscReal :: weight
> 
>    ind = mod(iter, max_srj)
>    weight = relaxation(ind)
>    call ksprichardsonsetscale(solver, weight, ierr)
>    if (ierr/=0) call abort(ierr, 'Failed to set the relaxation weights.', 
> nrank)
>    ierr = 0
> 
>    return
>  end subroutine MyKSPMonitor
> 
> 
>> On 27 Jul 2016, at 18:11, Barry Smith <[email protected]> wrote:
>> 
>> 
>>> On Jul 27, 2016, at 6:27 AM, JC <[email protected]> wrote:
>>> 
>>>> The dependence on grid size is easy.
>>> 
>>> Knowing the grid size, I have a list of files I can read to load the 
>>> correct relaxation weights. This is indeed the easy part.
>>> 
>>>> By depends on the iteration do you mean the linear iteration, as in the 
>>>> first iteration you use .1 then in the second you use .2 etc?
>>> 
>>> That is exactly what I meant. At the first iteration of the solver (i.e. 
>>> the first matrix-vector product), the relaxation is say omega_1. At the 
>>> second iteration, it is omega_2, so on so forth.
>>> 
>>>> To do this use KSPSetMonitor() and have your monitor routine call 
>>>> KSPRichardsonSetScale() with the value you like which can depend on the 
>>>> iteration.
>>> 
>>> So basically, KSPSetMonitor() allows me to define a callback procedure that 
>>> will be executed at the end of each iteration of the KSP solver, right?
>> 
>> Yes
>> 
>>> 
>>> Thanks a lot,
>>> JC
>> 
> 

Reply via email to