Date: 2026-03-31T05:46:38+00:00

Actual source code: sfregi.c

      1: #include <petsc/private/sfimpl.h>

      3: PETSC_INTERN PetscErrorCode PetscSFCreate_Basic(PetscSF);
      4: #if defined(PETSC_HAVE_MPI_WIN_CREATE)
      5: PETSC_INTERN PetscErrorCode PetscSFCreate_Window(PetscSF);
      6: #endif
      7: PETSC_INTERN PetscErrorCode PetscSFCreate_Allgatherv(PetscSF);
      8: PETSC_INTERN PetscErrorCode PetscSFCreate_Allgather(PetscSF);
      9: PETSC_INTERN PetscErrorCode PetscSFCreate_Gatherv(PetscSF);
     10: PETSC_INTERN PetscErrorCode PetscSFCreate_Gather(PetscSF);
     11: PETSC_INTERN PetscErrorCode PetscSFCreate_Alltoall(PetscSF);
     12: #if defined(PETSC_HAVE_MPI_NEIGHBORHOOD_COLLECTIVES)
     13: PETSC_INTERN PetscErrorCode PetscSFCreate_Neighbor(PetscSF);
     14: #endif

     16: PetscFunctionList PetscSFList;
     17: PetscBool         PetscSFRegisterAllCalled;

     19: /*@C
     20:   PetscSFRegisterAll - Registers all the `PetscSF` communication implementations

     22:   Not Collective

     24:   Level: advanced

     26: .seealso: `PetscSF`, `PetscSFRegister()`, `PetscSFRegisterDestroy()`
     27: @*/
     28: PetscErrorCode PetscSFRegisterAll(void)
     29: {
     30:   PetscFunctionBegin;
     31:   if (PetscSFRegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS);
     32:   PetscSFRegisterAllCalled = PETSC_TRUE;
     33:   PetscCall(PetscSFRegister(PETSCSFBASIC, PetscSFCreate_Basic));
     34: #if defined(PETSC_HAVE_MPI_WIN_CREATE)
     35:   PetscCall(PetscSFRegister(PETSCSFWINDOW, PetscSFCreate_Window));
     36: #endif
     37:   PetscCall(PetscSFRegister(PETSCSFALLGATHERV, PetscSFCreate_Allgatherv));
     38:   PetscCall(PetscSFRegister(PETSCSFALLGATHER, PetscSFCreate_Allgather));
     39:   PetscCall(PetscSFRegister(PETSCSFGATHERV, PetscSFCreate_Gatherv));
     40:   PetscCall(PetscSFRegister(PETSCSFGATHER, PetscSFCreate_Gather));
     41:   PetscCall(PetscSFRegister(PETSCSFALLTOALL, PetscSFCreate_Alltoall));
     42: #if defined(PETSC_HAVE_MPI_NEIGHBORHOOD_COLLECTIVES)
     43:   PetscCall(PetscSFRegister(PETSCSFNEIGHBOR, PetscSFCreate_Neighbor));
     44: #endif
     45:   PetscFunctionReturn(PETSC_SUCCESS);
     46: }

     48: /*@C
     49:   PetscSFRegister  - Adds an implementation of the `PetscSF` communication protocol.

     51:   Not Collective, No Fortran Support

     53:   Input Parameters:
     54: + name   - name of a new user-defined implementation
     55: - create - routine to create method context

     57:   Example Usage:
     58: .vb
     59:    PetscSFRegister("my_impl", MyImplCreate);
     60: .ve

     62:   Then, this implementation can be chosen with the procedural interface via
     63: .vb
     64:   PetscSFSetType(sf, "my_impl")
     65: .ve
     66:   or at runtime via the option
     67: .vb
     68:   -sf_type my_impl
     69: .ve

     71:   Level: advanced

     73:   Note:
     74:   `PetscSFRegister()` may be called multiple times to add several user-defined implementations.

     76: .seealso: `PetscSF`, `PetscSFType`, `PetscSFRegisterAll()`, `PetscSFInitializePackage()`
     77: @*/
     78: PetscErrorCode PetscSFRegister(const char name[], PetscErrorCode (*create)(PetscSF))
     79: {
     80:   PetscFunctionBegin;
     81:   PetscCall(PetscSFInitializePackage());
     82:   PetscCall(PetscFunctionListAdd(&PetscSFList, name, create));
     83:   PetscFunctionReturn(PETSC_SUCCESS);
     84: }