[petsc-users] Having trouble with basic Fortran-PETSc interoperability
Michael Whitten
mwhitte6 at jhu.edu
Fri Jan 2 13:42:41 CST 2026
Hi PETSc mailing list users,
I have managed to install PETSc and run some PETSc examples and little test codes of my own in Fortran. I am now trying to make PETSc work with my existing Fortran code. I have tried to build little test examples of the functionality that I can then incorporate into my larger code base. However, I am having trouble just passing vectors back and forth between PETSc and Fortran.
I have attached a minimum semi-working example that can be compiled with the standard 'Makefile.user'. It throws an error when I try to copy the PETSc vector back to a Fortran vector using VecGetValues(). I get that it can only access values of the array on the local process but how do I fix this? Is this even the right approach?
In the final implementation I want to be able to assemble my matrix and vector, convert them to PETSc data structures, use PETSc to solve, and then convert the solution vector back to Fortran and return. I want to be able to do this with both the linear and nonlinear solvers. It seems like this is what PETSc is, in part, built to do. Is this a reasonable expectation to achieve? Is this a reasonable use case for PETSc?
Thanks in advance for any help you can offer.
best,
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20260102/06bc1e89/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.F90
Type: text/x-fortran
Size: 1075 bytes
Desc: test.F90
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20260102/06bc1e89/attachment.bin>
More information about the petsc-users
mailing list