[petsc-users] Fortran: PetscScalar or double precision? Also: switch to F90 functions?

Smith, Barry F. bsmith at mcs.anl.gov
Tue Jul 3 10:40:13 CDT 2018


   Default ./configure of PETSc has PetscScalar being double precision; configure options can change it to single precision and or complex numbers. 

   If you are using the default configuration it should not matter if you declare your scalar variables as double precision or PetscScalar you should get the same results. Likely something else is wrong.

   We recommend upgrading to VecGetArrayF90() the resulting code is a little easier to read. But either way is fine for working code.

   Barry


> On Jul 3, 2018, at 10:21 AM, Bastian Löhrer <bastian.loehrer at tu-dresden.de> wrote:
> 
> Dear PETSc community,
> I'm working with a code that uses PETSc (version 3.3). We are about to upgrade our code to make it compatible with PETSc 3.9 but that's another story...
> 
> We have come across an issue which makes us wonder if we are handling the PETSc variables in the right way so it would be great if anyone of you could comment on the following code snippets:
> We include petsc_inlcude.h
> 
> 
>> ...
>>       Vec :: glob_p
>>       common /mpivector/  glob_p,   loc_p
>> ...
>> 
> 
> 
> in our main program file main.F90
>> ...
>> 
>> #include "./fluid/petsc_include.h"
>> 
>> ...
>> 
>>       PetscScalar loc_p_v(1)
>>       PetscOffset loc_p_i
>> ...
>>       call DMCreateGlobalVector(da1dof, glob_p  , ierr)
>>       call DMCreateLocalVector(da1dof,  loc_p   , ierr)
>>       call VecGetArray(loc_p,    loc_p_v,    loc_p_i,   ierr)
>> ...
>>       call SomeSubroutine ( loc_p_v     (loc_p_i  +1) )
>> 
>> 
> 
> as well as any other files containing subroutines. The issue we have is the observation that it now makes a difference how the argument of the subroutine is declared, i.e. p does not contain the same values in both of the following implementations:
>> subroutine SomeSubroutine( p )
>>    double precision, dimension(gis:gie,gjs:gje,gks:gke) :: p
>> 
> 
>> subroutine SomeSubroutine( p )
>>    PetscScalar p (gis:gie,gjs:gje,gks:gke)
>> 
> 
> This is puzzling to us, because we do have the PetscScalar configured as double precision real numbers.
> 
> I also noticed that we are using VecGetArray instead of VecGetArrayF90. Should we switch to the F90 version?
> 
> Kind regards
> Bastian Löhrer



More information about the petsc-users mailing list