1 #include <../src/vec/is/ao/aoimpl.h> /*I "petscao.h" I*/ 2 3 static PetscBool AOPackageInitialized = PETSC_FALSE; 4 static PetscBool AORegisterAllCalled = PETSC_FALSE; 5 6 /*@C 7 AOFinalizePackage - This function finalizes everything in the `AO` package. It is called 8 from `PetscFinalize()`. 9 10 Level: developer 11 12 .seealso: `AOInitializePackage()`, `PetscInitialize()` 13 @*/ 14 PetscErrorCode AOFinalizePackage(void) 15 { 16 PetscFunctionBegin; 17 PetscCall(PetscFunctionListDestroy(&AOList)); 18 AOPackageInitialized = PETSC_FALSE; 19 AORegisterAllCalled = PETSC_FALSE; 20 PetscFunctionReturn(PETSC_SUCCESS); 21 } 22 23 /*@C 24 AOInitializePackage - This function initializes everything in the `AO` package. It is called 25 from `PetscDLLibraryRegister_petscvec()` when using dynamic libraries, and on the first call to `AOCreate()` 26 when using static or shared libraries. 27 28 Level: developer 29 30 .seealso: `AOFinalizePackage()`, `PetscInitialize()` 31 @*/ 32 PetscErrorCode AOInitializePackage(void) 33 { 34 char logList[256]; 35 PetscBool opt, pkg; 36 37 PetscFunctionBegin; 38 if (AOPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS); 39 AOPackageInitialized = PETSC_TRUE; 40 /* Register Classes */ 41 PetscCall(PetscClassIdRegister("Application Order", &AO_CLASSID)); 42 /* Register Constructors */ 43 PetscCall(AORegisterAll()); 44 /* Register Events */ 45 PetscCall(PetscLogEventRegister("AOPetscToApplication", AO_CLASSID, &AO_PetscToApplication)); 46 PetscCall(PetscLogEventRegister("AOApplicationToPetsc", AO_CLASSID, &AO_ApplicationToPetsc)); 47 /* Process Info */ 48 { 49 PetscClassId classids[1]; 50 51 classids[0] = AO_CLASSID; 52 PetscCall(PetscInfoProcessClass("ao", 1, classids)); 53 } 54 /* Process summary exclusions */ 55 PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt)); 56 if (opt) { 57 PetscCall(PetscStrInList("ao", logList, ',', &pkg)); 58 if (pkg) PetscCall(PetscLogEventExcludeClass(AO_CLASSID)); 59 } 60 /* Register package finalizer */ 61 PetscCall(PetscRegisterFinalize(AOFinalizePackage)); 62 PetscFunctionReturn(PETSC_SUCCESS); 63 } 64 65 /*@C 66 AOSetType - Builds an application ordering for a particular `AOType` 67 68 Collective 69 70 Input Parameters: 71 + ao - The `AO` object 72 - method - The name of the AO type 73 74 Options Database Key: 75 . -ao_type <type> - Sets the `AO` type; use -help for a list of available types 76 77 Level: intermediate 78 79 Notes: 80 See "petsc/include/petscao.h" for available AO types (for instance, `AOBASIC` and `AOMEMORYSCALABLE`). 81 82 `AO` are usually created via the convenience routines such as `AOCreateBasic()` or `AOCreateMemoryScalable()` 83 84 .seealso: `AO`, `AOType`, `AOCreateBasic()`, `AOCreateMemoryScalable()`, `AOGetType()`, `AOCreate()` 85 @*/ 86 PetscErrorCode AOSetType(AO ao, AOType method) 87 { 88 PetscErrorCode (*r)(AO); 89 PetscBool match; 90 91 PetscFunctionBegin; 92 PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 93 PetscCall(PetscObjectTypeCompare((PetscObject)ao, method, &match)); 94 if (match) PetscFunctionReturn(PETSC_SUCCESS); 95 96 PetscCall(AORegisterAll()); 97 PetscCall(PetscFunctionListFind(AOList, method, &r)); 98 PetscCheck(r, PetscObjectComm((PetscObject)ao), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown AO type: %s", method); 99 PetscTryTypeMethod(ao, destroy); 100 ao->ops->destroy = NULL; 101 102 PetscCall((*r)(ao)); 103 PetscFunctionReturn(PETSC_SUCCESS); 104 } 105 106 /*@C 107 AOGetType - Gets the `AO` type name (as a string) from the AO. 108 109 Not Collective 110 111 Input Parameter: 112 . ao - The vector 113 114 Output Parameter: 115 . type - The `AO` type name 116 117 Level: intermediate 118 119 .seealso: `AO`, `AOType`, `AOSetType()`, `AOCreate()` 120 @*/ 121 PetscErrorCode AOGetType(AO ao, AOType *type) 122 { 123 PetscFunctionBegin; 124 PetscValidHeaderSpecific(ao, AO_CLASSID, 1); 125 PetscAssertPointer(type, 2); 126 PetscCall(AORegisterAll()); 127 *type = ((PetscObject)ao)->type_name; 128 PetscFunctionReturn(PETSC_SUCCESS); 129 } 130 131 /*--------------------------------------------------------------------------------------------------------------------*/ 132 133 PetscFunctionList AOList = NULL; 134 135 /*@C 136 AORegister - Register an application ordering method 137 138 Not Collective 139 140 Input Parameters: 141 + sname - the name (`AOType`) of the `AO` scheme 142 - function - the create routine for the application ordering method 143 144 Level: advanced 145 146 .seealso: `AO`, `AOType`, `AOCreate()`, `AORegisterAll()`, `AOBASIC`, `AOADVANCED`, `AOMAPPING`, `AOMEMORYSCALABLE` 147 @*/ 148 PetscErrorCode AORegister(const char sname[], PetscErrorCode (*function)(AO)) 149 { 150 PetscFunctionBegin; 151 PetscCall(AOInitializePackage()); 152 PetscCall(PetscFunctionListAdd(&AOList, sname, function)); 153 PetscFunctionReturn(PETSC_SUCCESS); 154 } 155 156 PETSC_INTERN PetscErrorCode AOCreate_Basic(AO ao); 157 PETSC_INTERN PetscErrorCode AOCreate_MemoryScalable(AO ao); 158 159 /*@C 160 AORegisterAll - Registers all of the application ordering components in the `AO` package. 161 162 Not Collective 163 164 Level: advanced 165 166 .seealso: `AO`, `AOType`, `AORegister()`, `AORegisterDestroy()` 167 @*/ 168 PetscErrorCode AORegisterAll(void) 169 { 170 PetscFunctionBegin; 171 if (AORegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS); 172 AORegisterAllCalled = PETSC_TRUE; 173 174 PetscCall(AORegister(AOBASIC, AOCreate_Basic)); 175 PetscCall(AORegister(AOMEMORYSCALABLE, AOCreate_MemoryScalable)); 176 PetscFunctionReturn(PETSC_SUCCESS); 177 } 178