Actual source code: aoreg.c
1: #include <../src/vec/is/ao/aoimpl.h>
3: static PetscBool AOPackageInitialized = PETSC_FALSE;
4: static PetscBool AORegisterAllCalled = PETSC_FALSE;
6: /*@C
7: AOFinalizePackage - This function finalizes everything in the `AO` package. It is called
8: from `PetscFinalize()`.
10: Level: developer
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: }
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.
28: Level: developer
30: .seealso: `AOFinalizePackage()`, `PetscInitialize()`
31: @*/
32: PetscErrorCode AOInitializePackage(void)
33: {
34: char logList[256];
35: PetscBool opt, pkg;
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];
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: }
65: /*@
66: AOSetType - Builds an application ordering for a particular `AOType`
68: Collective
70: Input Parameters:
71: + ao - The `AO` object
72: - method - The name of the AO type
74: Options Database Key:
75: . -ao_type <type> - Sets the `AO` type; use -help for a list of available types
77: Level: intermediate
79: Notes:
80: See "petsc/include/petscao.h" for available AO types (for instance, `AOBASIC` and `AOMEMORYSCALABLE`).
82: `AO` are usually created via the convenience routines such as `AOCreateBasic()` or `AOCreateMemoryScalable()`
84: .seealso: `AO`, `AOType`, `AOCreateBasic()`, `AOCreateMemoryScalable()`, `AOGetType()`, `AOCreate()`
85: @*/
86: PetscErrorCode AOSetType(AO ao, AOType method)
87: {
88: PetscErrorCode (*r)(AO);
89: PetscBool match;
91: PetscFunctionBegin;
93: PetscCall(PetscObjectTypeCompare((PetscObject)ao, method, &match));
94: if (match) PetscFunctionReturn(PETSC_SUCCESS);
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;
102: PetscCall((*r)(ao));
103: PetscFunctionReturn(PETSC_SUCCESS);
104: }
106: /*@
107: AOGetType - Gets the `AO` type name (as a string) from the AO.
109: Not Collective
111: Input Parameter:
112: . ao - The vector
114: Output Parameter:
115: . type - The `AO` type name
117: Level: intermediate
119: .seealso: `AO`, `AOType`, `AOSetType()`, `AOCreate()`
120: @*/
121: PetscErrorCode AOGetType(AO ao, AOType *type)
122: {
123: PetscFunctionBegin;
125: PetscAssertPointer(type, 2);
126: PetscCall(AORegisterAll());
127: *type = ((PetscObject)ao)->type_name;
128: PetscFunctionReturn(PETSC_SUCCESS);
129: }
131: PetscFunctionList AOList = NULL;
133: /*@C
134: AORegister - Register an application ordering method
136: Not Collective, No Fortran Support
138: Input Parameters:
139: + sname - the name (`AOType`) of the `AO` scheme
140: - function - the create routine for the application ordering method
142: Level: advanced
144: .seealso: `AO`, `AOType`, `AOCreate()`, `AORegisterAll()`, `AOBASIC`, `AOADVANCED`, `AOMAPPING`, `AOMEMORYSCALABLE`
145: @*/
146: PetscErrorCode AORegister(const char sname[], PetscErrorCode (*function)(AO))
147: {
148: PetscFunctionBegin;
149: PetscCall(AOInitializePackage());
150: PetscCall(PetscFunctionListAdd(&AOList, sname, function));
151: PetscFunctionReturn(PETSC_SUCCESS);
152: }
154: PETSC_INTERN PetscErrorCode AOCreate_Basic(AO ao);
155: PETSC_INTERN PetscErrorCode AOCreate_MemoryScalable(AO ao);
157: /*@C
158: AORegisterAll - Registers all of the application ordering components in the `AO` package.
160: Not Collective
162: Level: advanced
164: .seealso: `AO`, `AOType`, `AORegister()`, `AORegisterDestroy()`
165: @*/
166: PetscErrorCode AORegisterAll(void)
167: {
168: PetscFunctionBegin;
169: if (AORegisterAllCalled) PetscFunctionReturn(PETSC_SUCCESS);
170: AORegisterAllCalled = PETSC_TRUE;
172: PetscCall(AORegister(AOBASIC, AOCreate_Basic));
173: PetscCall(AORegister(AOMEMORYSCALABLE, AOCreate_MemoryScalable));
174: PetscFunctionReturn(PETSC_SUCCESS);
175: }