[petsc-dev] compiling PETSc Fortran program with modules

Adrian Croucher a.croucher at auckland.ac.nz
Thu Jun 5 00:49:09 CDT 2014


hi

I'm having trouble compiling a PETSc Fortran program, which uses a 
Fortran module in a separate file, which itself uses PETSc.

Here's a fairly minimal example of the problem.

Main program test.F90:
---
program test

   use my_module
   implicit none
#include <finclude/petsc.h90>
   PetscInt :: bar = 2

   print *, 'foo = ', foo, 'bar = ', bar

end program test
---


Module my_module.F90:
---
module my_module

   implicit none
#include <finclude/petsc.h90>
   PetscInt:: foo = 1

end module my_module
---

my_module.F90 will compile OK but when I compile test.F90 I get all 
kinds of errors like:

Error: Symbol 'mpi_file_null' at (1) conflicts with symbol from module 
'my_module'

presumably because I've included petsc.h90 twice. But if I don't have 
the include in both the module and the main program, I don't have access 
to PetscInt in both.

How does one get around this problem? I couldn't find any example 
problems using Fortran modules.

- Adrian

-- 
Dr Adrian Croucher
Senior Research Fellow
Department of Engineering Science
University of Auckland, New Zealand
email: a.croucher at auckland.ac.nz
tel: +64 (0)9 923 4611




More information about the petsc-dev mailing list