Actual source code: ex7f.F90

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

 12:        PetscScalar, parameter ::  two = 2.0
 13:        Vec              vec
 14:        MPI_Comm         comm
 15:        PetscErrorCode ierr
 16:        PetscMPIInt rank

 18: !
 19: !     The Objects vec,comm created in a C routine are now
 20: !     used in Fortran routines.
 21: !
 22:        PetscCall(VecSet(vec,two,ierr))
 23:        PetscCallMPI(MPI_Comm_rank(comm,rank,ierr))
 24:        PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr))

 26: !
 27: !  Now call routine from Fortran, passing in the vector, communicator
 28: !
 29:        PetscCall(ex7c(vec,comm,ierr))
 30: !
 31: !     IO from the Fortran routines may cause all kinds of
 32: !
 33: ! 100   format ('[',i1,']',' Calling VecView from Fortran')
 34: !       write(6,100) rank
 35: !
 36: !  Now Call a PETSc Routine from Fortran
 37: !
 38:        PetscCall(VecView(vec,PETSC_VIEWER_STDOUT_WORLD,ierr))
 39:        end