1 #include <petsc/private/partitionerimpl.h> /*I "petscpartitioner.h" I*/ 2 3 PetscClassId PETSCPARTITIONER_CLASSID = 0; 4 5 PetscFunctionList PetscPartitionerList = NULL; 6 PetscBool PetscPartitionerRegisterAllCalled = PETSC_FALSE; 7 8 /*@C 9 PetscPartitionerRegister - Adds a new PetscPartitioner implementation 10 11 Not Collective, No Fortran Support 12 13 Input Parameters: 14 + sname - The name of a new user-defined creation routine 15 - function - The creation routine 16 17 Notes: 18 PetscPartitionerRegister() may be called multiple times to add several user-defined PetscPartitioners 19 20 Example Usage: 21 .vb 22 PetscPartitionerRegister("my_part", MyPetscPartitionerCreate); 23 .ve 24 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 34 35 Level: advanced 36 37 .seealso: `PetscPartitionerRegisterAll()` 38 39 @*/ 40 PetscErrorCode PetscPartitionerRegister(const char sname[], PetscErrorCode (*function)(PetscPartitioner)) 41 { 42 PetscFunctionBegin; 43 PetscCall(PetscFunctionListAdd(&PetscPartitionerList, sname, function)); 44 PetscFunctionReturn(PETSC_SUCCESS); 45 } 46 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); 55 56 /*@C 57 PetscPartitionerRegisterAll - Registers all of the PetscPartitioner components in the DM package. 58 59 Not Collective 60 61 Level: advanced 62 63 .seealso: `PetscPartitionerRegister()`, `PetscPartitionerRegisterDestroy()` 64 @*/ 65 PetscErrorCode PetscPartitionerRegisterAll(void) 66 { 67 PetscFunctionBegin; 68 if (PetscPartitionerRegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS); 69 PetscPartitionerRegisterAllCalled = PETSC_TRUE; 70 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 } 81 82 static PetscBool PetscPartitionerPackageInitialized = PETSC_FALSE; 83 84 /*@C 85 PetscPartitionerFinalizePackage - This function finalizes everything in the PetscPartitioner package. 86 It is called from PetscFinalize(). 87 88 Level: developer 89 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 } 100 101 /*@C 102 PetscPartitionerInitializePackage - This function initializes everything in the PetscPartitioner package. 103 104 Level: developer 105 106 .seealso: `PetscInitialize()` 107 @*/ 108 PetscErrorCode PetscPartitionerInitializePackage(void) 109 { 110 char logList[256]; 111 PetscBool opt, pkg; 112 113 PetscFunctionBegin; 114 if (PetscPartitionerPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS); 115 PetscPartitionerPackageInitialized = PETSC_TRUE; 116 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]; 126 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]; 134 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 } 148