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()`
 38: @*/
 39: PetscErrorCode PetscPartitionerRegister(const char sname[], PetscErrorCode (*function)(PetscPartitioner))
 40: {
 41:   PetscFunctionBegin;
 42:   PetscCall(PetscFunctionListAdd(&PetscPartitionerList, sname, function));
 43:   PetscFunctionReturn(PETSC_SUCCESS);
 44: }

 46: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Multistage(PetscPartitioner);
 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);

 55: /*@C
 56:   PetscPartitionerRegisterAll - Registers all of the PetscPartitioner components in the DM package.

 58:   Not Collective

 60:   Level: advanced

 62: .seealso: `PetscPartitionerRegister()`, `PetscPartitionerRegisterDestroy()`
 63: @*/
 64: PetscErrorCode PetscPartitionerRegisterAll(void)
 65: {
 66:   PetscFunctionBegin;
 67:   if (PetscPartitionerRegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS);
 68:   PetscPartitionerRegisterAllCalled = PETSC_TRUE;

 70:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERPARMETIS, PetscPartitionerCreate_ParMetis));
 71:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERPTSCOTCH, PetscPartitionerCreate_PTScotch));
 72:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERCHACO, PetscPartitionerCreate_Chaco));
 73:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERSIMPLE, PetscPartitionerCreate_Simple));
 74:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERSHELL, PetscPartitionerCreate_Shell));
 75:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERGATHER, PetscPartitionerCreate_Gather));
 76:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERMATPARTITIONING, PetscPartitionerCreate_MatPartitioning));
 77:   PetscCall(PetscPartitionerRegister(PETSCPARTITIONERMULTISTAGE, PetscPartitionerCreate_Multistage));
 78:   PetscFunctionReturn(PETSC_SUCCESS);
 79: }

 81: static PetscBool PetscPartitionerPackageInitialized = PETSC_FALSE;

 83: /*@C
 84:   PetscPartitionerFinalizePackage - This function finalizes everything in the PetscPartitioner package.
 85:   It is called from PetscFinalize().

 87:   Level: developer

 89: .seealso: `PetscInitialize()`
 90: @*/
 91: PetscErrorCode PetscPartitionerFinalizePackage(void)
 92: {
 93:   PetscFunctionBegin;
 94:   PetscCall(PetscFunctionListDestroy(&PetscPartitionerList));
 95:   PetscPartitionerPackageInitialized = PETSC_FALSE;
 96:   PetscPartitionerRegisterAllCalled  = PETSC_FALSE;
 97:   PetscFunctionReturn(PETSC_SUCCESS);
 98: }

100: /*@C
101:   PetscPartitionerInitializePackage - This function initializes everything in the PetscPartitioner package.

103:   Level: developer

105: .seealso: `PetscInitialize()`
106: @*/
107: PetscErrorCode PetscPartitionerInitializePackage(void)
108: {
109:   char      logList[256];
110:   PetscBool opt, pkg;

112:   PetscFunctionBegin;
113:   if (PetscPartitionerPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
114:   PetscPartitionerPackageInitialized = PETSC_TRUE;

116:   /* Register Classes */
117:   PetscCall(PetscClassIdRegister("GraphPartitioner", &PETSCPARTITIONER_CLASSID));
118:   /* Register Constructors */
119:   PetscCall(PetscPartitionerRegisterAll());
120:   /* Register Events */
121:   {
122:     PetscCall(PetscLogEventRegister("PartMSSetUp", PETSCPARTITIONER_CLASSID, &PetscPartitioner_MS_SetUp));
123:     for (PetscInt event = 0; event < PETSCPARTITIONER_MS_NUMSTAGE; event++) {
124:       char ename[32];

126:       PetscCall(PetscSNPrintf(ename, sizeof(ename), "PartMSStage %" PetscInt_FMT, event));
127:       PetscCall(PetscLogEventRegister(ename, PETSCPARTITIONER_CLASSID, &PetscPartitioner_MS_Stage[event]));
128:     }
129:   }
130:   /* Process Info */
131:   {
132:     PetscClassId classids[1];

134:     classids[0] = PETSCPARTITIONER_CLASSID;
135:     PetscCall(PetscInfoProcessClass("partitioner", 1, classids));
136:   }
137:   /* Process summary exclusions */
138:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
139:   if (opt) {
140:     PetscCall(PetscStrInList("partitioner", logList, ',', &pkg));
141:     if (pkg) PetscCall(PetscLogEventExcludeClass(PETSCPARTITIONER_CLASSID));
142:   }
143:   /* Register package finalizer */
144:   PetscCall(PetscRegisterFinalize(PetscPartitionerFinalizePackage));
145:   PetscFunctionReturn(PETSC_SUCCESS);
146: }