[petsc-users] [Fortran] checking "ierr" return codes
Matthew Knepley
knepley at gmail.com
Tue Sep 7 06:51:12 CDT 2010
You can use CHKERRQ(ierr)
Matt
On Tue, Sep 7, 2010 at 12:03 PM, Leo van Kampenhout <
lvankampenhout at gmail.com> wrote:
> From the Petsc-manual:
>
> The user should check the return codes for all PETSc routines (and possibly
> user-defined routines as well)
> with
> ierr = PetscRoutine(...);CHKERRQ(PetscErrorCode ierr);
> Likewise, all memory allocations should be checked with
> ierr = PetscMalloc(n*sizeof(double),&ptr);CHKERRQ(ierr);
> If this procedure is followed throughout all of the user’s libraries and
> codes, any error will by default generate
> a clean traceback of the location of the error.
> Note that the macro __FUNCT__ is used to keep track of routine names
> during error tracebacks. Users
> need not worry about this macro in their application codes; however, users
> can take advantage of this feature
> if desired by setting this macro before each user-defined routine that may
> call SETERRQ(), CHKERRQ().
> A simple example of usage is given below.
> #undef FUNCT
> #define FUNCT ”MyRoutine1”
> int MyRoutine1() {
> /* code here */
> return 0;
> }
>
> My question is, what is the correct way do this in Fortran? I have seen
> the following variant in an example (ex35f90), but I couldn't get it to work
> myself. Also, it's tedious to copy this macro every time you start a new
> project.
>
> ! Error handler forces traceback of where error occurred
> subroutine HE2(ierr,line)
> use mex35f90
> use mex35f90interfaces
>
> call PetscError(ierr,line,0,'',ierr)
> return
> end
> #define CHKR(n) if(n .ne. 0)then;call HE2(n,__LINE__);return;endif
>
> Thanks in advance.
>
> Leo van Kampenhout
>
--
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/20100907/d05b34a7/attachment.htm>
More information about the petsc-users
mailing list