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: + name        - The name of a new user-defined creation routine
 15: - create_func - The creation routine itself

 17:   Notes:
 18:   PetscPartitionerRegister() may be called multiple times to add several user-defined PetscPartitioners

 20:   Sample 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: {

 45:   PetscFunctionListAdd(&PetscPartitionerList, sname, function);
 46:   return(0);
 47: }


 50: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_ParMetis(PetscPartitioner);
 51: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_PTScotch(PetscPartitioner);
 52: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Chaco(PetscPartitioner);
 53: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Shell(PetscPartitioner);
 54: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Simple(PetscPartitioner);
 55: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Gather(PetscPartitioner);
 56: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_MatPartitioning(PetscPartitioner);

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

 61:   Not Collective

 63:   Input parameter:
 64: . path - The dynamic library path

 66:   Level: advanced

 68: .seealso:  PetscPartitionerRegister(), PetscPartitionerRegisterDestroy()
 69: @*/
 70: PetscErrorCode PetscPartitionerRegisterAll(void)
 71: {

 75:   if (PetscPartitionerRegisterAllCalled) return(0);
 76:   PetscPartitionerRegisterAllCalled = PETSC_TRUE;

 78:   PetscPartitionerRegister(PETSCPARTITIONERPARMETIS, PetscPartitionerCreate_ParMetis);
 79:   PetscPartitionerRegister(PETSCPARTITIONERPTSCOTCH, PetscPartitionerCreate_PTScotch);
 80:   PetscPartitionerRegister(PETSCPARTITIONERCHACO,    PetscPartitionerCreate_Chaco);
 81:   PetscPartitionerRegister(PETSCPARTITIONERSIMPLE,   PetscPartitionerCreate_Simple);
 82:   PetscPartitionerRegister(PETSCPARTITIONERSHELL,    PetscPartitionerCreate_Shell);
 83:   PetscPartitionerRegister(PETSCPARTITIONERGATHER,   PetscPartitionerCreate_Gather);
 84:   PetscPartitionerRegister(PETSCPARTITIONERMATPARTITIONING, PetscPartitionerCreate_MatPartitioning);
 85:   return(0);
 86: }

 88: static PetscBool PetscPartitionerPackageInitialized = PETSC_FALSE;

 90: /*@C
 91:   PetscPartitionerFinalizePackage - This function finalizes everything in the PetscPartitioner package.
 92:   It is called from PetscFinalize().

 94:   Level: developer

 96: .seealso: PetscInitialize()
 97: @*/
 98: PetscErrorCode  PetscPartitionerFinalizePackage(void)
 99: {

103:   PetscFunctionListDestroy(&PetscPartitionerList);
104:   PetscPartitionerPackageInitialized = PETSC_FALSE;
105:   PetscPartitionerRegisterAllCalled  = PETSC_FALSE;
106:   return(0);
107: }

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

112:   Level: developer

114: .seealso: PetscInitialize()
115: @*/
116: PetscErrorCode  PetscPartitionerInitializePackage(void)
117: {
118:   char           logList[256];
119:   PetscBool      opt,pkg;

123:   if (PetscPartitionerPackageInitialized) return(0);
124:   PetscPartitionerPackageInitialized = PETSC_TRUE;

126:   /* Register Classes */
127:   PetscClassIdRegister("GraphPartitioner",&PETSCPARTITIONER_CLASSID);
128:   /* Register Constructors */
129:   PetscPartitionerRegisterAll();
130:   /* Register Events */
131:   /* Process Info */
132:   {
133:     PetscClassId  classids[1];

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