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