In the Fortran version, each PETSc routine has as its final argument
an integer error variable, in contrast to the C convention of
providing the error variable as the routine's return value. The error
code is set to be nonzero if an error has been detected; otherwise, it
is zero. For example, the Fortran and C variants of SLESSolve() are
given, respectively, below, where ierr denotes the error variable:
call SLESSolve(SLES sles,Vec b,Vec x,int its,int ierr) ierr = SLESSolve(SLES sles,Vec b,Vec x,int *its);Fortran programmers using the .F file suffix, as discussed in Section Include Files , can check these error codes with CHKERRA(ierr), which terminates all process when an error is encountered. Likewise, one can set error codes within Fortran programs by using SETERRA(ierr,p,' '), which again terminates all processes upon detection of an error. Note that complete error tracebacks with CHKERRQ() and SETERRQ(), as described in Section Simple PETSc Examples for C routines, are not directly supported for Fortran routines; however, Fortran programmers can easily use the error codes in writing their own tracebacks. For example, one could use code such as the following:
call SLESSolve(sles,x,y,ierr) if ( ierr .ne. 0 ) then print*, 'Error in routine ...' return endifNote that users of the Fortran .f suffix cannot employ the macros SETERRA() and CHKERRA().
The most common reason for crashing PETSc Fortran code is forgetting the final ierr argument.