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

 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_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:   PetscFunctionReturn(PETSC_SUCCESS);
 78: }

 80: static PetscBool PetscPartitionerPackageInitialized = PETSC_FALSE;

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

 86:   Level: developer

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

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

102:   Level: developer

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

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

115:   /* Register Classes */
116:   PetscCall(PetscClassIdRegister("GraphPartitioner", &PETSCPARTITIONER_CLASSID));
117:   /* Register Constructors */
118:   PetscCall(PetscPartitionerRegisterAll());
119:   /* Register Events */
120:   /* Process Info */
121:   {
122:     PetscClassId classids[1];

124:     classids[0] = PETSCPARTITIONER_CLASSID;
125:     PetscCall(PetscInfoProcessClass("partitioner", 1, classids));
126:   }
127:   /* Process summary exclusions */
128:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
129:   if (opt) {
130:     PetscCall(PetscStrInList("partitioner", logList, ',', &pkg));
131:     if (pkg) PetscCall(PetscLogEventExcludeClass(PETSCPARTITIONER_CLASSID));
132:   }
133:   /* Register package finalizer */
134:   PetscCall(PetscRegisterFinalize(PetscPartitionerFinalizePackage));
135:   PetscFunctionReturn(PETSC_SUCCESS);
136: }