xref: /petsc/src/vec/is/sf/utils/ftn-custom/zsfutilsf90.c (revision b0dcfd164860a975c76f90dabf1036901aab1c4e)
1*6dd63270SBarry Smith #include <petsc/private/ftnimpl.h>
2*6dd63270SBarry Smith #include <petscsf.h>
3*6dd63270SBarry Smith #include <petscsection.h>
4*6dd63270SBarry Smith 
5*6dd63270SBarry Smith #if defined(PETSC_HAVE_FORTRAN_CAPS)
6*6dd63270SBarry Smith   #define petscsfdestroyremoteoffsets_ PETSCSFDESTROYREMOTEOFFSETS
7*6dd63270SBarry Smith   #define petscsfdistributesection_    PETSCSFDISTRIBUTESECTION
8*6dd63270SBarry Smith   #define petscsfcreateremoteoffsets_  PETSCSFCREATEREMOTEOFFSETS
9*6dd63270SBarry Smith #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
10*6dd63270SBarry Smith   #define petscsfdestroyremoteoffsets_ petscsfdestroyremoteoffsets
11*6dd63270SBarry Smith   #define petscsfdistributesection_    petscsfdistributesection
12*6dd63270SBarry Smith   #define petscsfcreateremoteoffsets_  petscsfcreateremoteoffsets
13*6dd63270SBarry Smith #endif
14*6dd63270SBarry Smith 
petscsfdestroyremoteoffsets_(F90Array1d * ptr,int * ierr PETSC_F90_2PTR_PROTO (ptrd))15*6dd63270SBarry Smith PETSC_EXTERN void petscsfdestroyremoteoffsets_(F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
16*6dd63270SBarry Smith {
17*6dd63270SBarry Smith   PetscInt *fa;
18*6dd63270SBarry Smith   *ierr = F90Array1dAccess(ptr, MPIU_INT, (void **)&fa PETSC_F90_2PTR_PARAM(ptrd));
19*6dd63270SBarry Smith   if (*ierr) return;
20*6dd63270SBarry Smith   *ierr = F90Array1dDestroy(ptr, MPIU_INT PETSC_F90_2PTR_PARAM(ptrd));
21*6dd63270SBarry Smith   if (*ierr) return;
22*6dd63270SBarry Smith   *ierr = PetscFree(fa);
23*6dd63270SBarry Smith }
24*6dd63270SBarry Smith 
petscsfdistributesection_(PetscSF * sf,PetscSection * rootSection,F90Array1d * ptr,PetscSection * leafSection,int * ierr PETSC_F90_2PTR_PROTO (ptrd))25*6dd63270SBarry Smith PETSC_EXTERN void petscsfdistributesection_(PetscSF *sf, PetscSection *rootSection, F90Array1d *ptr, PetscSection *leafSection, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
26*6dd63270SBarry Smith {
27*6dd63270SBarry Smith   if (ptr == PETSC_NULL_INTEGER_POINTER_Fortran) {
28*6dd63270SBarry Smith     *ierr = PetscSFDistributeSection(*sf, *rootSection, NULL, *leafSection);
29*6dd63270SBarry Smith   } else {
30*6dd63270SBarry Smith     PetscInt *fa;
31*6dd63270SBarry Smith     PetscInt  lpStart, lpEnd;
32*6dd63270SBarry Smith 
33*6dd63270SBarry Smith     *ierr = PetscSFDistributeSection(*sf, *rootSection, &fa, *leafSection);
34*6dd63270SBarry Smith     if (*ierr) return;
35*6dd63270SBarry Smith     *ierr = PetscSectionGetChart(*leafSection, &lpStart, &lpEnd);
36*6dd63270SBarry Smith     if (*ierr) return;
37*6dd63270SBarry Smith     *ierr = F90Array1dCreate((void *)fa, MPIU_INT, 1, lpEnd - lpStart, ptr PETSC_F90_2PTR_PARAM(ptrd));
38*6dd63270SBarry Smith   }
39*6dd63270SBarry Smith }
40*6dd63270SBarry Smith 
petscsfcreateremoteoffsets_(PetscSF * pointSF,PetscSection * rootSection,PetscSection * leafSection,F90Array1d * ptr,int * ierr PETSC_F90_2PTR_PROTO (ptrd))41*6dd63270SBarry Smith PETSC_EXTERN void petscsfcreateremoteoffsets_(PetscSF *pointSF, PetscSection *rootSection, PetscSection *leafSection, F90Array1d *ptr, int *ierr PETSC_F90_2PTR_PROTO(ptrd))
42*6dd63270SBarry Smith {
43*6dd63270SBarry Smith   PetscInt *fa;
44*6dd63270SBarry Smith   PetscInt  lpStart, lpEnd;
45*6dd63270SBarry Smith 
46*6dd63270SBarry Smith   *ierr = PetscSFCreateRemoteOffsets(*pointSF, *rootSection, *leafSection, &fa);
47*6dd63270SBarry Smith   if (*ierr) return;
48*6dd63270SBarry Smith   *ierr = PetscSectionGetChart(*leafSection, &lpStart, &lpEnd);
49*6dd63270SBarry Smith   if (*ierr) return;
50*6dd63270SBarry Smith   *ierr = F90Array1dCreate((void *)fa, MPIU_INT, 1, lpEnd - lpStart, ptr PETSC_F90_2PTR_PARAM(ptrd));
51*6dd63270SBarry Smith }
52