[petsc-users] ksp_monitor_true_residual_norm
Jed Brown
jedbrown at mcs.anl.gov
Thu Apr 19 12:40:58 CDT 2012
It looks like this null object check was missing from the Fortran bindings.
Can you try with this patch included?
http://petsc.cs.iit.edu/petsc/petsc-dev/rev/05b5b9325f55
On Thu, Apr 19, 2012 at 10:12, Randall Mackie <rlmackie862 at gmail.com> wrote:
> Hi Matt and Barry,
>
> I tried this again, but this time I used a c subroutine like Barry
> suggested, which is this:
>
> #include "petsc.h"
>
> PetscErrorCode shellkspmonitor_(KSP ksp,PetscInt n,PetscReal rnorm,void
> *dummy)
> {
> PetscErrorCode ierr=0;
> if (n % 10) {
> ierr = KSPMonitorTrueResidualNorm(ksp,n,rnorm,dummy);CHKERRQ(ierr);
> }
>
> return ierr;
> }
>
>
> In my Fortran code, I declared shellkspmonitor as external, then I called
> KSPSetMonitor as follows:
>
> call KSPMonitorSet(ksp,shellkspmonitor,PETSC_NULL_OBJECT,
> PETSC_NULL_FUNCTION, ierr)
>
>
> But I am still getting the same error as before:
>
> [0]PETSC ERROR: [1]PETSC ERROR: [2]PETSC ERROR: [3]PETSC ERROR:
> --------------------- Error Message ------------------------------------
> --------------------- Error Message ------------------------------------
> [3]PETSC ERROR: [2]PETSC ERROR: Invalid argument!
> Invalid argument!
> [3]PETSC ERROR: Wrong type of object: Parameter # 1!
> [3]PETSC ERROR: [2]PETSC ERROR:
> ------------------------------------------------------------------------
> [3]PETSC ERROR: Petsc Release Version 3.2.0, Patch 5, Sat Oct 29 13:45:54
> CDT 2011
> [3]PETSC ERROR: --------------------- Error Message
> ------------------------------------
> [0]PETSC ERROR: Invalid argument!
> [0]PETSC ERROR: Wrong type of object: Parameter # 1!
> [0]PETSC ERROR:
> ------------------------------------------------------------------------
> [0]PETSC ERROR: Petsc Release Version 3.2.0, Patch 5, Sat Oct 29 13:45:54
> CDT 2011
> [0]PETSC ERROR: See docs/changes/index.html for recent updates.
> [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
> [0]PETSC ERROR: See docs/index.html for manual pages.
> [0]PETSC ERROR:
> ------------------------------------------------------------------------
> [0]PETSC ERROR: PetscViewerASCIIAddTab() line 277 in
> src/sys/viewer/impls/ascii/filev.c
> [0]PETSC ERROR: KSPMonitorTrueResidualNorm() line 233 in
> src/ksp/ksp/interface/iterativ.c
> [0]PETSC ERROR: shellkspmonitor_() line 7 in custom_monitor.c
> [3]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
> [3]PETSC ERROR: See docs/index.html for manual pages.
>
> So, there is either a problem in one of the PETSc routines, or the call
> from Fortran to KSPMonitorSet
> is wrong, although I have copied the calling sequence from the example in
> /src/ksp/ksp/examples/tutorials/ex2f.F
>
> In fact, you can reproduce this error using ex2f.F, simply swapping in the
> custom monitor above for
> the MyKSPMonitor of that example. I can send you the modified code and c
> subroutine to test if you want.
>
> Thanks, Randy
>
>
> On Tue, Apr 17, 2012 at 10:39 AM, Matthew Knepley <knepley at gmail.com>wrote:
>
>> On Tue, Apr 17, 2012 at 1:27 PM, Randall Mackie <rlmackie862 at gmail.com>wrote:
>>
>>> Hi Barry,
>>>
>>> I've tried implementing this in Fortran, following ex2f.F in
>>> /src/ksp/ksp/examples/tutorials, but
>>> it is bombing out with the following message:
>>>
>>> ---------------------- Error Message ------------------------------------
>>> [0]PETSC ERROR: Invalid argument!
>>> [0]PETSC ERROR: Wrong type of object: Parameter # 1!
>>> [0]PETSC ERROR:
>>> ------------------------------------------------------------------------
>>> [0]PETSC ERROR: Petsc Release Version 3.2.0, Patch 5, Sat Oct 29
>>> 13:45:54 CDT 2011
>>> -------------------- Error Message ------------------------------------
>>> [0]PETSC ERROR: Invalid argument!
>>> [0]PETSC ERROR: Wrong type of object: Parameter # 1!
>>> [0]PETSC ERROR:
>>> ------------------------------------------------------------------------
>>> [0]PETSC ERROR: Petsc Release Version 3.2.0, Patch 5, Sat Oct 29
>>> 13:45:54 CDT 2011
>>>
>>>
>>> [1]PETSC ERROR: PetscViewerASCIIAddTab() line 277 in
>>> src/sys/viewer/impls/ascii/filev.c
>>> [1]PETSC ERROR: KSPMonitorTrueResidualNorm() line 233 in
>>> src/ksp/ksp/interface/iterativ.c
>>> [1]PETSC ERROR: ourmonitor() line 103 in
>>> src/ksp/ksp/interface/ftn-custom/zitfuncf.c
>>> [1]PETSC ERROR: KSPMonitor() line 1429 in src/ksp/ksp/interface/itfunc.c
>>> [1]PETSC ERROR: KSPSolve_CG() line 255 in src/ksp/ksp/impls/cg/cg.c
>>> [1]PETSC ERROR: KSPSolve() line 423 in src/ksp/ksp/interface/itfunc.c
>>>
>>>
>>> I am running PETSC 3.2-p5.
>>>
>>> I have set my monitor routine as follows:
>>>
>>> subroutine ShellKSPMonitor(ksp, n, rnorm, dummy, ierr)
>>>
>>> implicit none
>>>
>>> #include "finclude/petsc.h"
>>>
>>> KSP :: ksp
>>> PetscErrorCode :: ierr
>>> PetscInt :: n, dummy
>>> PetscReal :: rnorm
>>>
>>> if (n == 200) then
>>> call KSPMonitorTrueResidualNorm(ksp,n,rnorm,dummy,ierr)
>>>
>>
>> I think it should work if dummy is 0, but we should really do NULL
>> conversion
>> here and you should pass PETSC_NULL.
>>
>> Matt
>>
>>
>>> end if
>>>
>>> return
>>> end subroutine ShellKSPMonitor
>>>
>>> And then in the main program I call:
>>>
>>> call KSPMonitorSet(ksp,ShellKSPMonitor,PETSC_NULL_OBJECT,
>>> PETSC_NULL_FUNCTION, ierr)
>>>
>>> As I have followed the example in the PETSc documentation, I am unsure
>>> where I have made a mistake.
>>>
>>> Thanks,
>>>
>>> Randy M
>>>
>>>
>>> On Fri, Apr 13, 2012 at 5:01 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>
>>>>
>>>> Write a one line monitor that calls the true residual monitor when
>>>> desired:
>>>>
>>>> PetscErrorCode myKSPMonitorTrueResidualNorm(KSP ksp,PetscInt
>>>> n,PetscReal rnorm,void *dummy)
>>>> {
>>>> if (n % 10) {
>>>> ierr =
>>>> KSPMonitorTrueResidualNorm(ksp,n,rnorm,dummy);CHKERRQ(ierr);
>>>> }
>>>> }
>>>>
>>>> then call this on the KPS
>>>>
>>>> ierr =
>>>> KSPMonitorSet(ksp,myKSPMonitorTrueResidualNorm,PETSC_VIEWER_STDOUT,0);CHKERRQ(ierr);
>>>>
>>>>
>>>> On Apr 13, 2012, at 6:52 PM, Randall Mackie wrote:
>>>>
>>>> > In using ksp_monitor_true_residual_norm, is it possible to change how
>>>> often this information is printed out?
>>>> > That is, instead of every iteration, say I only want to see it every
>>>> 10 or 20 iterations. Is there an easy way
>>>> > to do this, other than creating my own monitor and doing it myself?
>>>> >
>>>> > Thanks, Randy M.
>>>>
>>>>
>>>
>>
>>
>> --
>> 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120419/70eb17f9/attachment.htm>
More information about the petsc-users
mailing list