[petsc-dev] PetscSF in Fortran

Barry Smith bsmith at mcs.anl.gov
Tue Oct 24 17:34:10 CDT 2017


   This didn't last too long 

/opt/atlassian/pipelines/agent/build/src/sys/f90-src/f90_cwrap.c: In function 'PetscErrorCode PetscMPIFortranDatatypeToC(MPI_Fint, MPI_Datatype*)':
/opt/atlassian/pipelines/agent/build/src/sys/f90-src/f90_cwrap.c:29:16: error: 'MPI_INTEGER' was not declared in this scope
   if (ftype == MPI_INTEGER) *dtype = MPI_INT;
                ^
/opt/atlassian/pipelines/agent/build/src/sys/f90-src/f90_cwrap.c:30:21: error: 'MPI_DOUBLE_PRECISION' was not declared in this scope
   else if (ftype == MPI_DOUBLE_PRECISION) *dtype = MPI_DOUBLE;
                     ^
/opt/atlassian/pipelines/agent/build/src/sys/f90-src/f90_cwrap.c:31:21: error: 'MPI_COMPLEX16' was not declared in this scope
   else if (ftype == MPI_COMPLEX16) *dtype = MPI_C_DOUBLE_COMPLEX;
                     ^


> On Oct 24, 2017, at 6:58 AM, Jed Brown <jed at jedbrown.org> wrote:
> 
> Lawrence Mitchell <wencel at gmail.com> writes:
> 
>>> On 24 Oct 2017, at 06:21, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>> 
>>>>>> - With PetscSFBcastBegin() / PetscSFBcastEnd() you currently still have to use the C MPI types in the Fortran calling code, rather than the Fortran ones. I think it is a bit confusing to have to mix the two up in the same code. If you put MPI_INTEGER instead of MPI_INT for example, it dies in F90Array1dAccess() with 'unsupported MPI_Datatype'. Could the Fortran MPI types be supported in these routines just by adding them as alternatives into the conditionals?
>>>>> Hmm, Jed will need to provide wisdom the Linux manual page for MPI_INTEGER clearly states:
>>>>> 
>>>>> Note that the Fortran types should only be used in Fortran programs, and the C types should only be used in C programs. For example, it is in error to use MPI_INT for a Fortran INTEGER. Datatypes are of type MPI_Datatype in C and of type INTEGER in Fortran.
>>>>> 
>>>>> If this is true then there is no place we can do the change properly.
>>>> 
>>>> Yes, I first thought that MPI_Type_f2c() would convert Fortran MPI datatypes to the C ones (e.g. turn MPI_INTEGER into MPI_INT), so that the C side of the interface wouldn't have to worry about the Fortran MPI datatypes, but it doesn't really seem to do that.
>>> 
>>> Do did I. Its existence seems to contradict the statement in the Linux manual page. Well wait for Jed.
>> 
>> A fortran INTEGER may have a different width to a C int.  Hence the distinction.  The MPI_XXX_f2c functions convert handles on the fortran side to handles on the C side (MPI_XXX_c2f does the opposite).  Perhaps the standard sheds some light:
>> 
>> Moving handles from Fortran to C
>> 
>> http://mpi-forum.org/docs/mpi-3.1/mpi31-report/node446.htm#Node446
> 
> Thanks, Lawrence.  And my recollection is that the C types are
> guaranteed to exist if the MPI was built to support Fortran, but may not
> be defined otherwise.  So PETSc uses it in code that is only compiled
> when Fortran is available, it should all work.
> 
>> Interlanguage communication
>> 
>> http://mpi-forum.org/docs/mpi-3.1/mpi31-report/node456.htm#Node456
>> 
>> Lawrence



More information about the petsc-dev mailing list