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