Actual source code: ex7f.F90

  1: ! Demonstrates how a computational module may be written
  2: ! in Fortran and called from a C routine, passing down PETSc objects.
  3: #include <petsc/finclude/petscvec.h>
  4: subroutine ex7f(vec, comm)
  5:   use petscvec
  6:   implicit none

  8:   Vec vec
  9:   MPIU_Comm comm
 10:   PetscErrorCode ierr
 11:   PetscMPIInt rank
 12:   PetscScalar, parameter :: two = 2.0

 14: ! The Objects vec,comm created in a C routine are now
 15: ! used in Fortran routines.
 16:   PetscCall(VecSet(vec, two, ierr))
 17:   PetscCallMPI(MPI_Comm_rank(comm, rank, ierr))
 18:   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr))

 20: ! Now call routine from Fortran, passing in the vector, communicator
 21:   PetscCall(ex7c(vec, comm, ierr))

 23: ! IO from the Fortran routines may cause all kinds of
 24: !
 25: ! 100 format ('[',i1,']',' Calling VecView from Fortran')
 26: ! write(6,100) rank
 27: !
 28: ! Now Call a PETSc Routine from Fortran
 29: !
 30:   PetscCall(VecView(vec, PETSC_VIEWER_STDOUT_WORLD, ierr))
 31: end