Actual source code: partitionerreg.c
1: #include <petsc/private/partitionerimpl.h>
3: PetscClassId PETSCPARTITIONER_CLASSID = 0;
5: PetscFunctionList PetscPartitionerList = NULL;
6: PetscBool PetscPartitionerRegisterAllCalled = PETSC_FALSE;
8: /*@C
9: PetscPartitionerRegister - Adds a new PetscPartitioner implementation
11: Not Collective, No Fortran Support
13: Input Parameters:
14: + sname - The name of a new user-defined creation routine
15: - function - The creation routine
17: Notes:
18: PetscPartitionerRegister() may be called multiple times to add several user-defined PetscPartitioners
20: Example Usage:
21: .vb
22: PetscPartitionerRegister("my_part", MyPetscPartitionerCreate);
23: .ve
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
35: Level: advanced
37: .seealso: `PetscPartitionerRegisterAll()`
39: @*/
40: PetscErrorCode PetscPartitionerRegister(const char sname[], PetscErrorCode (*function)(PetscPartitioner))
41: {
42: PetscFunctionBegin;
43: PetscCall(PetscFunctionListAdd(&PetscPartitionerList, sname, function));
44: PetscFunctionReturn(PETSC_SUCCESS);
45: }
47: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Multistage(PetscPartitioner);
48: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_ParMetis(PetscPartitioner);
49: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_PTScotch(PetscPartitioner);
50: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Chaco(PetscPartitioner);
51: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Shell(PetscPartitioner);
52: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Simple(PetscPartitioner);
53: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Gather(PetscPartitioner);
54: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_MatPartitioning(PetscPartitioner);
56: /*@C
57: PetscPartitionerRegisterAll - Registers all of the PetscPartitioner components in the DM package.
59: Not Collective
61: Level: advanced
63: .seealso: `PetscPartitionerRegister()`, `PetscPartitionerRegisterDestroy()`
64: @*/
65: PetscErrorCode PetscPartitionerRegisterAll(void)
66: {
67: PetscFunctionBegin;
68: if (PetscPartitionerRegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS);
69: PetscPartitionerRegisterAllCalled = PETSC_TRUE;
71: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERPARMETIS, PetscPartitionerCreate_ParMetis));
72: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERPTSCOTCH, PetscPartitionerCreate_PTScotch));
73: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERCHACO, PetscPartitionerCreate_Chaco));
74: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERSIMPLE, PetscPartitionerCreate_Simple));
75: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERSHELL, PetscPartitionerCreate_Shell));
76: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERGATHER, PetscPartitionerCreate_Gather));
77: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERMATPARTITIONING, PetscPartitionerCreate_MatPartitioning));
78: PetscCall(PetscPartitionerRegister(PETSCPARTITIONERMULTISTAGE, PetscPartitionerCreate_Multistage));
79: PetscFunctionReturn(PETSC_SUCCESS);
80: }
82: static PetscBool PetscPartitionerPackageInitialized = PETSC_FALSE;
84: /*@C
85: PetscPartitionerFinalizePackage - This function finalizes everything in the PetscPartitioner package.
86: It is called from PetscFinalize().
88: Level: developer
90: .seealso: `PetscInitialize()`
91: @*/
92: PetscErrorCode PetscPartitionerFinalizePackage(void)
93: {
94: PetscFunctionBegin;
95: PetscCall(PetscFunctionListDestroy(&PetscPartitionerList));
96: PetscPartitionerPackageInitialized = PETSC_FALSE;
97: PetscPartitionerRegisterAllCalled = PETSC_FALSE;
98: PetscFunctionReturn(PETSC_SUCCESS);
99: }
101: /*@C
102: PetscPartitionerInitializePackage - This function initializes everything in the PetscPartitioner package.
104: Level: developer
106: .seealso: `PetscInitialize()`
107: @*/
108: PetscErrorCode PetscPartitionerInitializePackage(void)
109: {
110: char logList[256];
111: PetscBool opt, pkg;
113: PetscFunctionBegin;
114: if (PetscPartitionerPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
115: PetscPartitionerPackageInitialized = PETSC_TRUE;
117: /* Register Classes */
118: PetscCall(PetscClassIdRegister("GraphPartitioner", &PETSCPARTITIONER_CLASSID));
119: /* Register Constructors */
120: PetscCall(PetscPartitionerRegisterAll());
121: /* Register Events */
122: {
123: PetscCall(PetscLogEventRegister("PartMSSetUp", PETSCPARTITIONER_CLASSID, &PetscPartitioner_MS_SetUp));
124: for (PetscInt event = 0; event < PETSCPARTITIONER_MS_NUMSTAGE; event++) {
125: char ename[32];
127: PetscCall(PetscSNPrintf(ename, sizeof(ename), "PartMSStage %" PetscInt_FMT, event));
128: PetscCall(PetscLogEventRegister(ename, PETSCPARTITIONER_CLASSID, &PetscPartitioner_MS_Stage[event]));
129: }
130: }
131: /* Process Info */
132: {
133: PetscClassId classids[1];
135: classids[0] = PETSCPARTITIONER_CLASSID;
136: PetscCall(PetscInfoProcessClass("partitioner", 1, classids));
137: }
138: /* Process summary exclusions */
139: PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
140: if (opt) {
141: PetscCall(PetscStrInList("partitioner", logList, ',', &pkg));
142: if (pkg) PetscCall(PetscLogEventExcludeClass(PETSCPARTITIONER_CLASSID));
143: }
144: /* Register package finalizer */
145: PetscCall(PetscRegisterFinalize(PetscPartitionerFinalizePackage));
146: PetscFunctionReturn(PETSC_SUCCESS);
147: }