[petsc-users] petsc with fortran modules
Smith, Barry F.
bsmith at mcs.anl.gov
Sun Nov 5 13:36:08 CST 2017
> On Nov 3, 2017, at 5:41 PM, Satish Balay <balay at mcs.anl.gov> wrote:
>
> On Fri, 3 Nov 2017, Ed D'Azevedo wrote:
>
>> Dear PETSc expert,
>>
>> I have a question on the correct way to use Fortran module in petsc.
>>
>> In this url on "UsingFortran"
>>
>>
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/UsingFortran.html#UsingFortran
>>
>>
>> it mentions including both the "petsc/finclude/petscXXX.h" file and the
>> Fortran "use" statement.
>>
>> The example show the following:
>>
>>
>> #include "petsc/finclude/petscvec.h"
>> use petscvec
>>
>> Vec b
>> type(tVec) x
>
> Just to note: its either of the above 2 statements.
I do not understand Satish's comment. You are free to declare vectors in either of the two ways above. You can mix them if you want though that would be confusing and we definitely don't recommend it. We recommend using one or the other consistently as
Vec b,x
or
type(tVec) x,b
Ed,
The change for handling Fortran in PETSc is dramatic, and vastly improves Fortran usage. We absolutely recommend that you just switch to the new format and the new release. It is in no way reasonable to expect to use both the current version of PETSc and previous versions with your same code by sticking some of your own #ifdef in your Fortran code based on the version. You need to just upgrade and stay upgraded.
Barry
>
>>
>>
>> My understanding of Fortran syntax is there cannot be "parameter" statements
>> before the module "use" statement or in other words "use" statement cannot
>> follow "parameter" statement.
>>
>> Do I understand correctly then all ".h" include header files under
>> "petsc/finclude/" should not have "parameter" statements but just pure cpp
>> macro statements such as "#define" or "#ifdef"?
>
> yes.
>
> balay at asterix /home/balay/petsc ((v3.8))
> $ grep parameter include/petsc/finclude/*
> include/petsc/finclude/petscsys.h:! F90 uses real(), conjg() when KIND parameter is used.
> balay at asterix /home/balay/petsc ((v3.8))
> $
>
>>
>> One may imagine substituting "parameter" statements with '#define' such as
>> instead of
>>
>> parameter (NOT_SET_VALUES=0)
>>
>> #define NOT_SET_VALUES 0
>>
>> #define not_set_values 0
>>
>> In the petsc version 3.6.2 under include/petsc/finclude, there seems to be
>> some files such as petscvec.h and petscmat.h that contain "parameter"
>> statements.
>
> The above doc corresponds to petsc-3.8 (with major changes for fortran
> module usage) - which is an upgrade we recommend for fortran usage.
>
>>
>>
>>
>> If there should be "parameter" statements in the petsc/finclude header files,
>> perhaps the order of the code should be to list all F90 module "use"
>> statements first, then include 'petsc/finclude' header files?
>
> For older releases - we split paramaters and #defines into different
> set of includes. So one would use to get only the #defines
>
> #define "petscdef.h"
>
>
> Satish
>
>>
>>
>> !
>> ------------------------------------------------------------------------------
>>
>> ! parameter statements after the module use statement
>>
>> !
>> ------------------------------------------------------------------------------
>>
>> use petscvec
>>
>> #include "petsc/finclude/petscvec.h"
>>
>> Vec b
>> type(tVec) x
>>
>>
>>
More information about the petsc-users
mailing list