xref: /petsc/src/dm/partitioner/interface/partitionerreg.c (revision 21e3ffae2f3b73c0bd738cf6d0a809700fc04bb0)
1 #include <petsc/private/partitionerimpl.h> /*I "petscpartitioner.h" I*/
2 
3 PetscClassId PETSCPARTITIONER_CLASSID = 0;
4 
5 PetscFunctionList PetscPartitionerList              = NULL;
6 PetscBool         PetscPartitionerRegisterAllCalled = PETSC_FALSE;
7 
8 /*@C
9   PetscPartitionerRegister - Adds a new PetscPartitioner implementation
10 
11   Not Collective
12 
13   Input Parameters:
14 + name        - The name of a new user-defined creation routine
15 - create_func - The creation routine itself
16 
17   Notes:
18   PetscPartitionerRegister() may be called multiple times to add several user-defined PetscPartitioners
19 
20   Sample usage:
21 .vb
22     PetscPartitionerRegister("my_part", MyPetscPartitionerCreate);
23 .ve
24 
25   Then, your PetscPartitioner type can be chosen with the procedural interface via
26 .vb
27     PetscPartitionerCreate(MPI_Comm, PetscPartitioner *);
28     PetscPartitionerSetType(PetscPartitioner, "my_part");
29 .ve
30    or at runtime via the option
31 .vb
32     -petscpartitioner_type my_part
33 .ve
34 
35   Level: advanced
36 
37 .seealso: `PetscPartitionerRegisterAll()`
38 
39 @*/
40 PetscErrorCode PetscPartitionerRegister(const char sname[], PetscErrorCode (*function)(PetscPartitioner))
41 {
42   PetscFunctionBegin;
43   PetscCall(PetscFunctionListAdd(&PetscPartitionerList, sname, function));
44   PetscFunctionReturn(PETSC_SUCCESS);
45 }
46 
47 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_ParMetis(PetscPartitioner);
48 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_PTScotch(PetscPartitioner);
49 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Chaco(PetscPartitioner);
50 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Shell(PetscPartitioner);
51 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Simple(PetscPartitioner);
52 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Gather(PetscPartitioner);
53 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_MatPartitioning(PetscPartitioner);
54 
55 /*@C
56   PetscPartitionerRegisterAll - Registers all of the PetscPartitioner components in the DM package.
57 
58   Not Collective
59 
60   Input parameter:
61 . path - The dynamic library path
62 
63   Level: advanced
64 
65 .seealso: `PetscPartitionerRegister()`, `PetscPartitionerRegisterDestroy()`
66 @*/
67 PetscErrorCode PetscPartitionerRegisterAll(void)
68 {
69   PetscFunctionBegin;
70   if (PetscPartitionerRegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS);
71   PetscPartitionerRegisterAllCalled = PETSC_TRUE;
72 
73   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERPARMETIS, PetscPartitionerCreate_ParMetis));
74   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERPTSCOTCH, PetscPartitionerCreate_PTScotch));
75   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERCHACO, PetscPartitionerCreate_Chaco));
76   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERSIMPLE, PetscPartitionerCreate_Simple));
77   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERSHELL, PetscPartitionerCreate_Shell));
78   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERGATHER, PetscPartitionerCreate_Gather));
79   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERMATPARTITIONING, PetscPartitionerCreate_MatPartitioning));
80   PetscFunctionReturn(PETSC_SUCCESS);
81 }
82 
83 static PetscBool PetscPartitionerPackageInitialized = PETSC_FALSE;
84 
85 /*@C
86   PetscPartitionerFinalizePackage - This function finalizes everything in the PetscPartitioner package.
87   It is called from PetscFinalize().
88 
89   Level: developer
90 
91 .seealso: `PetscInitialize()`
92 @*/
93 PetscErrorCode PetscPartitionerFinalizePackage(void)
94 {
95   PetscFunctionBegin;
96   PetscCall(PetscFunctionListDestroy(&PetscPartitionerList));
97   PetscPartitionerPackageInitialized = PETSC_FALSE;
98   PetscPartitionerRegisterAllCalled  = PETSC_FALSE;
99   PetscFunctionReturn(PETSC_SUCCESS);
100 }
101 
102 /*@C
103   PetscPartitionerInitializePackage - This function initializes everything in the PetscPartitioner package.
104 
105   Level: developer
106 
107 .seealso: `PetscInitialize()`
108 @*/
109 PetscErrorCode PetscPartitionerInitializePackage(void)
110 {
111   char      logList[256];
112   PetscBool opt, pkg;
113 
114   PetscFunctionBegin;
115   if (PetscPartitionerPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
116   PetscPartitionerPackageInitialized = PETSC_TRUE;
117 
118   /* Register Classes */
119   PetscCall(PetscClassIdRegister("GraphPartitioner", &PETSCPARTITIONER_CLASSID));
120   /* Register Constructors */
121   PetscCall(PetscPartitionerRegisterAll());
122   /* Register Events */
123   /* Process Info */
124   {
125     PetscClassId classids[1];
126 
127     classids[0] = PETSCPARTITIONER_CLASSID;
128     PetscCall(PetscInfoProcessClass("partitioner", 1, classids));
129   }
130   /* Process summary exclusions */
131   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
132   if (opt) {
133     PetscCall(PetscStrInList("partitioner", logList, ',', &pkg));
134     if (pkg) PetscCall(PetscLogEventExcludeClass(PETSCPARTITIONER_CLASSID));
135   }
136   /* Register package finalizer */
137   PetscCall(PetscRegisterFinalize(PetscPartitionerFinalizePackage));
138   PetscFunctionReturn(PETSC_SUCCESS);
139 }
140