[petsc-users] Issues linking petsc header files and lib from FORTRAN codes

Jianbo Long longtuteng249 at gmail.com
Thu Nov 3 19:58:12 CDT 2022


Hello,

I'm struggling to make my FORTRAN code work with petsc as I cannot link the
required header files (e.g., petscksp.h) and compiled library files to my
FORTRAN code.

Compiling petsc was not a problem. However, even with the fortran examples
(see those on https://petsc.org/main/docs/manual/fortran/) and the guide on
using petsc in c++ and fortran codes (see Section "Writing C/C++ or Fortran
Applications" at https://petsc.org/main/docs/manual/getting_started/), I
still cannot make my FORTRAN code work.

The Fortran test code is exactly the example code ex83f.F90 (see attached
files). Aftering following the 2nd method in the Guide (see the picture
below), I still get errors:

petsc/finclude/petscksp.h: No such file or directory

Even if I set up the path of the header file correctly in my own makefile
without using environment variables, I still can only find the file
"petscksp.h" for my code. Of course, the trouble is that all other headers
files required by KSP are recursively included in this petscksp.h file, and
I have no way to link them together for my Fortran code.

So, here are my questions:
1) in the Guide, how exactly are we supposed to set up the environment
variables  PETSC_DIR  and PETSC_ARCH ? More details and examples would be
extremely helpful !
2) Is there a way to get rid of the *preprocessor* statement
 #include <petsc/finclude/petscvec.h>
when using c++/Fortran codes ?

For example, when using MUMPS package in a Fortran code, we can simply use
*compiler* 'include', rather than a preprocessor, to extract all required
variables for the user's codes :
  INCLUDE 'zmumps_struc.h'
where the header file zmumps_struc.h is already provided in the package.
Similarly, I think it's much more portable and easier when using petsc in
other codes if we can make it work to use petsc.

(Note: similar issues were discussed before, see
https://lists.mcs.anl.gov/mailman/htdig/petsc-users/2019-January/037499.html.
Unfortunately, I have no clue about the solution archived there ...)

Any thoughts and solutions would be much appreciated !

Thanks,
Jianbo Long

[image: image.png]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221104/b2543283/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 277283 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221104/b2543283/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ex83f.F90
Type: text/x-fortran
Size: 4251 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221104/b2543283/attachment-0001.bin>


More information about the petsc-users mailing list