xref: /petsc/src/vec/is/sf/interface/sfregi.c (revision 1c84c290429673533d0af1ef36b216eb00726fbb)
1 #include <petsc-private/sfimpl.h>     /*I  "petscsf.h"  I*/
2 
3 #if defined(PETSC_HAVE_MPI_WIN_CREATE)
4 PETSC_EXTERN PetscErrorCode PetscSFCreate_Window(PetscSF);
5 #endif
6 PETSC_EXTERN PetscErrorCode PetscSFCreate_Basic(PetscSF);
7 
8 PetscFunctionList PetscSFunctionList;
9 
10 #undef __FUNCT__
11 #define __FUNCT__ "PetscSFRegisterAll"
12 /*@C
13    PetscSFRegisterAll - Registers all the PetscSF communication implementations
14 
15    Not Collective
16 
17    Level: advanced
18 
19 .keywords: PetscSF, register, all
20 
21 .seealso:  PetscSFRegisterDestroy()
22 @*/
23 PetscErrorCode  PetscSFRegisterAll(const char path[])
24 {
25   PetscErrorCode ierr;
26 
27   PetscFunctionBegin;
28   PetscSFRegisterAllCalled = PETSC_TRUE;
29 #if defined(PETSC_HAVE_MPI_WIN_CREATE) && defined(PETSC_HAVE_MPI_TYPE_DUP)
30   ierr = PetscSFRegister(PETSCSFWINDOW,       path,"PetscSFCreate_Window",       PetscSFCreate_Window);CHKERRQ(ierr);
31 #endif
32   ierr = PetscSFRegister(PETSCSFBASIC,        path,"PetscSFCreate_Basic",        PetscSFCreate_Basic);CHKERRQ(ierr);
33   PetscFunctionReturn(0);
34 }
35 
36 #undef __FUNCT__
37 #define __FUNCT__ "PetscSFRegister"
38 /*@C
39   PetscSFRegister  - Adds an implementation of the PetscSF communication protocol.
40 
41    Not collective
42 
43    Input Parameters:
44 +  name_impl - name of a new user-defined implementation
45 .  name_create - name of routine to create method context
46 -  routine_create - routine to create method context
47 
48    Notes:
49    PetscSFRegister() may be called multiple times to add several user-defined implementations.
50 
51    Sample usage:
52 .vb
53    PetscSFRegister("my_impl","MyImplCreate",MyImplCreate);
54 .ve
55 
56    Then, this implementation can be chosen with the procedural interface via
57 $     PetscSFSetType(sf,"my_impl")
58    or at runtime via the option
59 $     -snes_type my_solver
60 
61    Level: advanced
62 
63 .keywords: PetscSF, register
64 
65 .seealso: PetscSFRegisterAll(), PetscSFRegisterDestroy()
66 @*/
67 PetscErrorCode  PetscSFRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(PetscSF))
68 {
69   char           fullname[PETSC_MAX_PATH_LEN];
70   PetscErrorCode ierr;
71 
72   PetscFunctionBegin;
73   ierr = PetscFunctionListConcat(path,name,fullname);CHKERRQ(ierr);
74   ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&PetscSFunctionList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
75   PetscFunctionReturn(0);
76 }
77 
78 #undef __FUNCT__
79 #define __FUNCT__ "PetscSFRegisterDestroy"
80 /*@
81    PetscSFRegisterDestroy - Frees the list of communication implementations registered by PetscSFRegister()
82 
83    Not Collective
84 
85    Level: advanced
86 
87 .keywords: PetscSF, register, destroy
88 
89 .seealso: PetscSFRegisterAll()
90 @*/
91 PetscErrorCode  PetscSFRegisterDestroy(void)
92 {
93   PetscErrorCode ierr;
94 
95   PetscFunctionBegin;
96   ierr = PetscFunctionListDestroy(&PetscSFunctionList);CHKERRQ(ierr);
97 
98   PetscSFRegisterAllCalled = PETSC_FALSE;
99   PetscFunctionReturn(0);
100 }
101