[petsc-users] Using fortran modules in petsc

Barry Smith bsmith at mcs.anl.gov
Tue Jul 26 14:32:26 CDT 2011


   We cannot handle winmail.dat attachments.

   Seems likely you have ierr declared both in the module and in your routine, and the compiler cannot handle that. Since you are using ierr as an argument to your subroutines I don't think you should be declaring it in the module at all.

   Barry

On Jul 26, 2011, at 1:18 PM, Haren, S.W. van (Steven) wrote:

> Dear all,
> 
> I try to use fortran modules to have the same variable declarations over my main program and all my subroutines.
> 
> My module file looks like:
> 
> module variables
> #include "finclude/petscsys.h"
> #include "finclude/petscvec.h"
> #include "finclude/petscmat.h"
> #include "finclude/petscpc.h"
> #include "finclude/petscksp.h"
> #include "finclude/petscviewer.h"
> 
> type::mesh_type      
>         PetscScalar      x1,x2,y1,y2,Lx,Ly,deltax,deltay,ratiox,ratioy
>         PetscInt         Nx,Ny,Npx,Npy,Np,Nux_b,Nux_in,Nux_t,Nuy_b,Nuy_in,Nuy_t,Nu_t,Nb
>         PetscInt         Nvx_b,Nvx_in,Nvx_t,Nvy_b,Nvy_in,Nvy_t,Nv_t,N1,N2,N3,N4
> end type mesh_type
> type(mesh_type)::mesh
> 
> etc................
> 
> My main program looks like:
> 
> program main
> 
> 
>      use variables      
> 
>      implicit none
> 
> etc.................
> 
> Then a subroutine looks like:
> 
> subroutine parameters(mesh,flowParameters,ierr)      
> 
>      use variables
> 
>      implicit none
> 
> etc...................
> 
> I have my makefile set up to first compile the module, then the main program, and then all the subroutines. The module and the main program compile just fine. However, if I try to use one of the variables from the module in the subroutine I get the following compiler error:
> 
>      print *,ierr
>                  1
> Error: Name 'ierr' at (1) is an ambiguous reference to 'ierr' from current program unit
> 
> Any tips to resolve this issue would be very helpful. I could manually declare all the variables in the main program and all the subroutines (this is how I did it before and it works fine). However, my program is growing and for efficiency reasons I would really like to have all the variable declarations in one single file.
> 
> Kind regards,
> 
> Steven
> 
> 
> 
> 
> 
> 
> <winmail.dat>



More information about the petsc-users mailing list