Actual source code: ex43f.F90
2: module ex43fmodule
3: #include <petsc/finclude/petscvec.h>
4: use,intrinsic :: iso_c_binding
5: interface
6: subroutine fillupvector(vaddr,err) bind ( C, name = "fillupvector")
7: !
8: ! We need to use iso_c_binding variables or otherwise we get compiler warnings
9: ! Warning: Variable 'vaddr' at (1) is a dummy argument of the BIND(C)
10: ! procedure 'fillupvector' but may not be C interoperable
11: !
12: use,intrinsic :: iso_c_binding
13: integer(c_long_long) vaddr
14: integer(c_int) err
15: end subroutine fillupvector
16: end interface
17: end module
19: #include <petsc/finclude/petscvec.h>
20: use,intrinsic :: iso_c_binding
21: use petscvec
22: use ex43fmodule
23: implicit none
24: !
25: ! This routine demonstrates how to call a bind C function from Fortran
26: Vec v
27: PetscErrorCode ierr
28: PetscInt five
29: !
30: ! We need to use the same iso_c_binding variable types here or some compilers
31: ! will see a type mismatch in the call to fillupvector and thus not link
32: !
33: integer(c_long_long) vaddr
34: integer(c_int) err
36: PetscCallA(PetscInitialize(ierr))
37: PetscCallA(VecCreate(PETSC_COMM_WORLD,v,ierr))
38: five = 5
39: PetscCallA(VecSetSizes(v,PETSC_DECIDE,five,ierr))
40: PetscCallA(VecSetFromOptions(v,ierr))
41: !
42: ! Now Call a Petsc Routine from Fortran
43: !
44: !
45: vaddr = v%v
46: call fillupvector(vaddr,err)
48: PetscCallA(VecView(v,PETSC_VIEWER_STDOUT_WORLD,ierr))
49: PetscCallA(VecDestroy(v,ierr))
50: PetscCallA(PetscFinalize(ierr))
51: end
53: !/*TEST
54: !
55: ! build:
56: ! depends: ex43.c
57: !
58: ! test:
59: !
60: !TEST*/