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: {
 42:   PetscFunctionListAdd(&PetscPartitionerList, sname, function);
 43:   return 0;
 44: }

 46: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_ParMetis(PetscPartitioner);
 47: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_PTScotch(PetscPartitioner);
 48: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Chaco(PetscPartitioner);
 49: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Shell(PetscPartitioner);
 50: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Simple(PetscPartitioner);
 51: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Gather(PetscPartitioner);
 52: PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_MatPartitioning(PetscPartitioner);

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

 57:   Not Collective

 59:   Input parameter:
 60: . path - The dynamic library path

 62:   Level: advanced

 64: .seealso:  PetscPartitionerRegister(), PetscPartitionerRegisterDestroy()
 65: @*/
 66: PetscErrorCode PetscPartitionerRegisterAll(void)
 67: {
 68:   if (PetscPartitionerRegisterAllCalled) return 0;
 69:   PetscPartitionerRegisterAllCalled = PETSC_TRUE;

 71:   PetscPartitionerRegister(PETSCPARTITIONERPARMETIS, PetscPartitionerCreate_ParMetis);
 72:   PetscPartitionerRegister(PETSCPARTITIONERPTSCOTCH, PetscPartitionerCreate_PTScotch);
 73:   PetscPartitionerRegister(PETSCPARTITIONERCHACO,    PetscPartitionerCreate_Chaco);
 74:   PetscPartitionerRegister(PETSCPARTITIONERSIMPLE,   PetscPartitionerCreate_Simple);
 75:   PetscPartitionerRegister(PETSCPARTITIONERSHELL,    PetscPartitionerCreate_Shell);
 76:   PetscPartitionerRegister(PETSCPARTITIONERGATHER,   PetscPartitionerCreate_Gather);
 77:   PetscPartitionerRegister(PETSCPARTITIONERMATPARTITIONING, PetscPartitionerCreate_MatPartitioning);
 78:   return 0;
 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:   PetscFunctionListDestroy(&PetscPartitionerList);
 94:   PetscPartitionerPackageInitialized = PETSC_FALSE;
 95:   PetscPartitionerRegisterAllCalled  = PETSC_FALSE;
 96:   return 0;
 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:   if (PetscPartitionerPackageInitialized) return 0;
112:   PetscPartitionerPackageInitialized = PETSC_TRUE;

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

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