[petsc-dev] PetscSF in Fortran

Matthew Knepley knepley at gmail.com
Wed Oct 18 12:45:50 CDT 2017


On Tue, Oct 17, 2017 at 11:35 PM, Adrian Croucher <a.croucher at auckland.ac.nz
> wrote:

> hi
>
> On 16/10/17 15:16, Jed Brown wrote:
>
>> Adrian Croucher <a.croucher at auckland.ac.nz> writes:
>>
>> So do you think the SF stuff in petsc/finclude/petscis.h should be taken
>>> out, and put into a new petsc/finclude/petscsf.h ?
>>>
>> I think that's desirable for symmetry with include/petscsf.h, but it
>> isn't important for your contribution.
>>
>
> I have got Fortran bindings for PetscSFGetGraph() and PetscSFSetGraph()
> working. First I tried separating the existing SF stuff out of the IS
> modules, but ran into dependency problems in other modules. I wasn't too
> confident about the best way to resolve those without breaking things, so I
> tried it again just doing minimal changes to the existing SF stuff-
> essentially just adding Fortran wrappers for PetscSFGetGraph() and
> PetscSFSetGraph() into src/vec/f90-mod/petscis.h90- and that seemed to work
> fine. Maybe someone more familiar with the setup could separate out the SF
> stuff from IS sometime.
>
>
> So, now I'm trying to add Fortran bindings for PetscSFBcastBegin() and
> PetscSFBcastEnd().
>
> From the C side I have added the following into
> src/vec/is/sf/interface/f90-custom/zsff90.c:
>
> PETSC_EXTERN void PETSC_STDCALL petscsfbcastbegin_(PetscSF *sf,
> MPI_Datatype *unit, F90Array1d *rptr, F90Array1d *lptr , int *ierr
> PETSC_F90_2PTR_PROTO(rptrd) PETSC_F90_2PTR_PROTO(lptrd))
> {
>   PetscDataType ptype;
>   const void* rootdata;
>   void* leafdata;
>
>   *ierr = PetscMPIDataTypeToPetscDataType(*unit, &ptype);if (*ierr)
> return;
>   *ierr = F90Array1dAccess(rptr, ptype, (void**) &rootdata
> PETSC_F90_2PTR_PARAM(rptrd));if (*ierr) return;
>   *ierr = F90Array1dAccess(lptr, ptype, (void**) &leafdata
> PETSC_F90_2PTR_PARAM(lptrd));if (*ierr) return;
>
>   *ierr = PetscSFBcastBegin(*sf, *unit, rootdata, leafdata);
>
> }
>
> and similarly for petscsfbcastend_(). Does this look plausible?
>
> Then some wrappers need to be added to src/vec/f90-mod/petscis.h90. I am
> not sure how to do those.
>
> The difficulty is in declaring the arrays that are passed in, which can be
> of various types. In C they are declared as void*, but I'm not sure what to
> do with that in Fortran. I can't seem to find any other example wrappers in
> PETSc to model it on either. Any suggestions?


I do not understand Fortran. However, it looks like you can choose an
arbitrary type for the array, such as character,
and then use the 'transfer' intrinsic from F95 in your code to get an array
like that

  https://jblevins.org/log/transfer

so you only need an interface with that generic array type in PETSc.

   Matt


> - Adrian
>
> --
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> University of Auckland, New Zealand
> email: a.croucher at auckland.ac.nz
> tel: +64 (0)9 923 4611
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.caam.rice.edu/~mk51/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20171018/bfc02301/attachment.html>


More information about the petsc-dev mailing list