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