Programming in *.f90 free format with PETSc
Paul T. Bauman
pbauman at ices.utexas.edu
Tue Aug 7 08:29:14 CDT 2007
Hi Ben,
Here is the format I use in my .f90 modules. Note I do not know what
the standard is, but this "style" has worked with ifort, gfortran, g95
and Visual Studio (so I'm told).
module IAmAModule
implicit none
private !(you don't need this if you don't want it)
#PREPROCESSING STATEMENTS HERE (these will be seen by all subroutines
contained in the module)
public :: whatever needs to be public
integer :: declare variables you want in the module
contains
subroutine IAmASubroutine (note this format works for a subroutine not
in a module
implicit none
#PREPROCESSING STATEMENTS NOT INCLUDED IN THE MODULE
variable declarations
code here...
end subroutine IAmASubroutine
end module IAmAModule
It looks like in your case below, the preprocessing statements are
before the program - they must be inside the program. Put them after
implicit none and before any variable declarations (in case you use a
PETSc type variable).
Good Luck,
Paul
Ben Tay wrote:
> Hi,
>
> I can compile and run with visual fortran by putting all the
> declarations inside a subroutine e.g.
>
> module ada
>
> ...
>
> subroutine ddd
>
>
> #define PETSC_AVOID_DECLARATIONS
> #include "include/finclude/ petsc.h"
> <other includes>
> #undef PETSC_AVOID_DECLARATIONS
>
> ....
>
> end subroutine ddd
>
>
> end module ada
>
> However, on my school's server which uses ifort, I get errors both
> using your way and my way e.g.
>
>
> #define PETSC_AVOID_DECLARATIONS
> #include "include/finclude/petsc.h"
> #include "include/finclude/petscvec.h"
> #include "include/finclude/petscmat.h"
> #include "include/finclude/petscksp.h"
> #include "include/finclude/petscpc.h"
> #include "include/finclude/petscmat.h90"
> #undef PETSC_AVOID_DECLARATIONS
>
> program test
>
> implicit none
>
> integer :: x,y
>
> Vec test_vec
>
> x=1
>
> print *, x
>
> end program test
>
>
> I compile using
>
> ifort -r8 -132 -fPIC -g -c -static-libcxa -O3
> -I/lsftmp/g0306332/petsc-2.3.3-p0
> -I/lsftmp/g0306332/petsc-2.3.3-p0/bmake/atlas3
> -I/lsftmp/g0306332/petsc-2.3.3-p0/include
> -I/lsftmp/g0306332/petsc-2.3.3-p0/externalpackages/hypre-
> 2.0.0/atlas3/include -I/lsftmp/g0306332/mpich2/include temp.f90
>
> and get the error msg:
>
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
> fortcom: Warning: Bad # preprocessor line
>
> fortcom: Error: temp.f90, line 18: Syntax error, found IDENTIFIER
> 'TEST_VEC' when expecting one of: => = . ( : %
> Vec test_vec
> ----^
> fortcom: Error: temp.f90, line 18: This name does not have a type, and
> must have an explicit type. [VEC]
> Vec test_vec
> ^
> fortcom: Error: temp.f90, line 18: This name does not have a type, and
> must have an explicit type. [TEST_VEC]
> Vec test_vec
> ----^
> compilation aborted for temp.f90 (code 1)
>
> I also tried shifting the declarations after the "program test" line
> but it also failed. There is no problem if I changed the code to fixed
> format.
>
> Thanks
>
>
>
>
> On 8/6/07, *Satish Balay* <balay at mcs.anl.gov
> <mailto:balay at mcs.anl.gov>> wrote:
>
> This is incorrect usage.
>
> If you are getting errors with the correct usage, send us the error
> messages, with your code, and we can sugest fixes.
>
> - one issue could be
>
> > > #define PETSC_AVOID_DECLARATIONS
> > > #include "include/finclude/petsc.h"
> > > #include "include/finclude/petscvec.h90" <--- This should be
> removed from here..
> > > <other includes>
> > > #undef PETSC_AVOID_DECLARATIONS
> > >
> > > moudle foobar
> > > <other module stuff>
> > > end module
>
>
> Satish
>
> On Mon, 6 Aug 2007, Ben Tay wrote:
>
> > Hi,
> >
> > I tried to use
> >
> > #define PETSC_AVOID_DECLARATIONS
> > #include "include/finclude/petsc.h"
> > <other includes>
> > #undef PETSC_AVOID_DECLARATIONS
> >
> >
> > module ada
> > ...
> >
> > subroutine ....
> >
> > end module ada
> >
> > but the compiler says that the module is placed in the wrong
> order. Anyway, I
> > just move the top 4 lines into the subroutine instead and it
> worked. Thanks
> >
> > module ada
> >
> > ...
> >
> > subroutine ddd
> >
> > #define PETSC_AVOID_DECLARATIONS
> > #include "include/finclude/petsc.h"
> > <other includes>
> > #undef PETSC_AVOID_DECLARATIONS
> >
> > ....
> >
> > end subroutine ddd
> >
> >
> >
> >
> > Satish Balay wrote:
> > > you can use .F90 suffix for free-from preprocesed code. [or use
> > > compiler options to force it always use free-form]
> > >
> > > And when using fortran modules use the following organization:
> > >
> > >
> > > #define PETSC_AVOID_DECLARATIONS
> > > #include "include/finclude/petsc.h"
> > > <other includes>
> > > #undef PETSC_AVOID_DECLARATIONS
> > >
> > > moudle foobar
> > > <other module stuff>
> > > end module
> > >
> > > subroutine xyz()
> > > use foobar
> > > implicit none
> > > #include "include/finclude/petsc.h"
> > > <other includes>
> > > <code>
> > > end subroutine
> > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> > >
> > > Satish
> > >
> > > On Mon, 6 Aug 2007, Ben Tay wrote:
> > >
> > >
> > > > Hi,
> > > >
> > > > I've no problem writing out codes in fortran fixed format
> with PETSc.
> > > > However,
> > > > is it possible to do it in fortran free format as well?
> > > >
> > > > I'm using visual fortran and there's error.
> > > >
> > > > original :
> > > >
> > > > test.F
> > > >
> > > > module global_data
> > > >
> > > > implicit none
> > > >
> > > > save
> > > >
> > > > #include "include/finclude/petsc.h"
> > > > #include "include/finclude/petscvec.h"
> > > > #include "include/finclude/petscmat.h"
> > > > #include "include/finclude/petscksp.h"
> > > > #include "include/finclude/petscpc.h"
> > > > #include "include/finclude/petscmat.h90"
> > > >
> > > > Vec xx,b_rhs
> > > >
> > > > ....
> > > >
> > > > How can I change this code to fortran free format *.f90?
> > > >
> > > > Thanks
> > > >
> > > >
> > > >
> > >
> > >
> > >
> >
> >
>
>
More information about the petsc-users
mailing list