[petsc-users] [Fortran] checking "ierr" return codes

Leo van Kampenhout lvankampenhout at gmail.com
Tue Sep 7 05:03:34 CDT 2010


>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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100907/f3748ff8/attachment.htm>


More information about the petsc-users mailing list