petsc-3.7.1 2016-05-15
Report Typos and Errors

# UsingFortran

Fortran can be used with PETSc in four distinct approaches

       1) classic Fortran 77 style

.#include "petsc/finclude/petscXXX.h" to work with material from the XXX component of PETSc

          XXX variablename

         You cannot use this approach if you wish to use the Fortran 90 specific PETSc routines

         which end in F90; such as VecGetArrayF90()

       2) classic Fortran 90 style

.#include "petsc/finclude/petscXXX.h" .#include "petsc/finclude/petscXXX.h90" to work with material from the XXX component of PETSc

          XXX variablename

       3) Using Fortran modules

.#include "petsc/finclude/petscXXXdef.h"

            use petscXXXX

          XXX variablename

       4) Use Fortran modules and Fortran data types for PETSc types

.#include "petsc/finclude/petscXXXdef.h"

            use petscXXXX

          type(XXX) variablename

         To use this approach you must ./configure PETSc with the additional

         option --with-fortran-datatypes You cannot use the type(XXX) declaration approach without using Fortran modules

Finally if you absolutely do not want to use any #include you can use either Many br

       3a) skip the #include BUT you cannot use any PETSc data type names like Vec, Mat, PetscInt, PetscErrorCode etc

           and you must declare the variables as integer, for example

           integer variablename

       4a) skip the #include, you use the object types like type(Vec) type(Mat) but cannot use the data type

           names like PetscErrorCode, PetscInt etc. again for those you must use integer

We recommend either 2 or 3. Approaches 2 and 3 provide type checking for most PETSc function calls; 4 has type checking Many brfor only a few PETSc functions. Many br

Fortran type checking with interfaces is strick, this means you cannot pass a scalar value when an array value Many bris expected (even though it is legal Fortran). For example when setting a single value in a matrix with MatSetValues() Many bryou cannot have something like Many br

         PetscInt row,col

         PetscScalar val

           ...

         call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr)

You must instead have Many br

         PetscInt row(1),col(1)

         PetscScalar val(1)

           ...

         call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr)

See the example src/vec/vec/examples/tutorials/ex20f90.F90 for an example that can use all four approaches Many br

Developer Notes: The petsc/finclude/petscXXXdef.h contain all the #defines (would be typedefs in C code) these Many brautomatically include their predecessors; for example petsc/finclude/petscvecdef.h includes petsc/finclude/petscisdef.h Many br

The petsc/finclude/petscXXXX.h contain all the parameter statements for that package. These automatically include Many brtheir petsc/finclude/petscXXXdef.h file but DO NOT automatically include their predecessors; for example Many brpetsc/finclude/petscvec.h does NOT automatically include petsc/finclude/petscis.h Many br

The petsc/finclude/ftn-custom/petscXXXdef.h90 are not intended to be used directly in code, they define the Many brFortran data type type(XXX) (for example type(Vec)) when PETSc is ./configure with the --with-fortran-datatypes option. Many br

The petsc/finclude/ftn-custom/petscXXX.h90 (not included directly by code) contain interface definitions for Many brthe PETSc Fortran stubs that have different bindings then their C version (for example VecGetArrayF90). Many br

The petsc/finclude/ftn-auto/petscXXX.h90 (not included directly by code) contain interface definitions generated Many brautomatically by "make allfortranstubs". Many br

The petsc/finclude/petscXXX.h90 includes the custom petsc/finclude/ftn-custom/petscXXX.h90 and if ./configure Many brwas run with --with-fortran-interfaces it also includes the petsc/finclude/ftn-auto/petscXXX.h90 These DO NOT automatically Many brinclude their predecessors Many br

Many br

Level:beginner
Location:include/petscsys.h
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages src/vec/vec/examples/tutorials/ex20f90.F90.html