[petsc-dev] For Fortran users of PETSc development version

Barry Smith bsmith at mcs.anl.gov
Sun Dec 4 11:57:52 CST 2016


    For Fortran users of the PETSc development (git master branch) version


    I have updated and simplified the Fortran usage of PETSc in the past few weeks. I will put the branch barry/fortran-update into the master branch on Monday. The usage changes are

A)  for each Fortran function (and main) use the following

       subroutine mysubroutine(.....)
#include <petsc/finclude/petscxxx.h>
       use petscxxx
       implicit none

     For example if you are using SNES in your code you would have 

#include <petsc/finclude/petscsnes.h>
       use petscsnes
       implicit none

B) Instead of PETSC_NULL_OBJECT you must pass PETSC_NULL_XXX (for example PETSC_NULL_VEC) using the specific object type XXX that the function call is expecting.

C) Objects can be declared either as XXX  a  or  type(iXXX) a, for example Mat a or type(iMat) a.  (Note that previously for those who used types it was type(Mat) but that can no longer be used.

Notes:

1)   There are no longer any .h90 files that may be included

2)    Like C the include files are now nested so you no longer need to include for example

#include <petsc/finclude/petscsys.h>
#include <petsc/finclude/petscvec.h>
#include <petsc/finclude/petscmat.h>
#include <petsc/finclude/petscpc.h>
#include <petsc/finclude/petscksp.h>

you can just include 

#include <petsc/finclude/petscksp.h>

3) there is now type checking of most function calls. This will help eliminate bugs due to incorrect calling sequences. Note that Fortran distinguishes between a argument that is a scalar (zero dimensional array), a one dimensional array and a two dimensional array (etc). So you may get compile warnings because you are passing in an array when PETSc expects a scalar or vis-versa. If you get these simply fix your declaration of the variable to match what is expected. In some routines like MatSetValues() and friends you can pass either scalars, one dimensional arrays or two dimensional arrays, if you get errors here please send mail to petsc-maint at mcs.anl.gov and include enough of your code so we can see the dimensions of all your variables so we can fix the problems.

4) You can continue to use either fixed (.F extension) or free format (.F90 extension) for your source

5) All the examples in PETSc have been updated so consult them for clarifications.


  Please report any problems to petsc-maint at mcs.anl.gov

   Thanks

   Barry





More information about the petsc-dev mailing list