xref: /petsc/src/vec/is/sf/interface/sfregi.c (revision dd5b3ca66ca4de5e00e985c205d0f80060c552e8)
1 #include <petsc/private/sfimpl.h>     /*I  "petscsf.h"  I*/
2 
3 PETSC_EXTERN PetscErrorCode PetscSFCreate_Basic(PetscSF);
4 #if defined(PETSC_HAVE_MPI_WIN_CREATE) && defined(PETSC_HAVE_MPI_TYPE_DUP)
5 PETSC_EXTERN PetscErrorCode PetscSFCreate_Window(PetscSF);
6 PETSC_INTERN PetscErrorCode PetscSFCreate_Allgatherv(PetscSF);
7 PETSC_INTERN PetscErrorCode PetscSFCreate_Allgather(PetscSF);
8 PETSC_INTERN PetscErrorCode PetscSFCreate_Gatherv(PetscSF);
9 PETSC_INTERN PetscErrorCode PetscSFCreate_Gather(PetscSF);
10 PETSC_INTERN PetscErrorCode PetscSFCreate_Alltoall(PetscSF);
11 #endif
12 
13 PetscFunctionList PetscSFList;
14 PetscBool         PetscSFRegisterAllCalled;
15 
16 /*@C
17    PetscSFRegisterAll - Registers all the PetscSF communication implementations
18 
19    Not Collective
20 
21    Level: advanced
22 
23 .seealso:  PetscSFRegisterDestroy()
24 @*/
25 PetscErrorCode  PetscSFRegisterAll(void)
26 {
27   PetscErrorCode ierr;
28 
29   PetscFunctionBegin;
30   if (PetscSFRegisterAllCalled) PetscFunctionReturn(0);
31   PetscSFRegisterAllCalled = PETSC_TRUE;
32   ierr = PetscSFRegister(PETSCSFBASIC,  PetscSFCreate_Basic);CHKERRQ(ierr);
33 #if defined(PETSC_HAVE_MPI_WIN_CREATE) && defined(PETSC_HAVE_MPI_TYPE_DUP)
34   ierr = PetscSFRegister(PETSCSFWINDOW, PetscSFCreate_Window);CHKERRQ(ierr);
35 #endif
36   ierr = PetscSFRegister(PETSCSFALLGATHERV,PetscSFCreate_Allgatherv);CHKERRQ(ierr);
37   ierr = PetscSFRegister(PETSCSFALLGATHER, PetscSFCreate_Allgather);CHKERRQ(ierr);
38   ierr = PetscSFRegister(PETSCSFGATHERV,   PetscSFCreate_Gatherv);CHKERRQ(ierr);
39   ierr = PetscSFRegister(PETSCSFGATHER,    PetscSFCreate_Gather);CHKERRQ(ierr);
40   ierr = PetscSFRegister(PETSCSFALLTOALL,  PetscSFCreate_Alltoall);CHKERRQ(ierr);
41   PetscFunctionReturn(0);
42 }
43 
44 /*@C
45   PetscSFRegister  - Adds an implementation of the PetscSF communication protocol.
46 
47    Not collective
48 
49    Input Parameters:
50 +  name - name of a new user-defined implementation
51 -  create - routine to create method context
52 
53    Notes:
54    PetscSFRegister() may be called multiple times to add several user-defined implementations.
55 
56    Sample usage:
57 .vb
58    PetscSFRegister("my_impl",MyImplCreate);
59 .ve
60 
61    Then, this implementation can be chosen with the procedural interface via
62 $     PetscSFSetType(sf,"my_impl")
63    or at runtime via the option
64 $     -sf_type my_impl
65 
66    Level: advanced
67 
68 .seealso: PetscSFRegisterAll(), PetscSFInitializePackage()
69 @*/
70 PetscErrorCode  PetscSFRegister(const char name[],PetscErrorCode (*create)(PetscSF))
71 {
72   PetscErrorCode ierr;
73 
74   PetscFunctionBegin;
75   ierr = PetscSFInitializePackage();CHKERRQ(ierr);
76   ierr = PetscFunctionListAdd(&PetscSFList,name,create);CHKERRQ(ierr);
77   PetscFunctionReturn(0);
78 }
79