xref: /petsc/src/vec/is/ao/interface/aoreg.c (revision 55e7fe800d976e85ed2b5cd8bfdef564daa37bd9)
1 
2 #include <../src/vec/is/ao/aoimpl.h>    /*I "petscao.h"  I*/
3 
4 PetscFunctionList AOList              = NULL;
5 PetscBool         AORegisterAllCalled = PETSC_FALSE;
6 
7 /*@C
8   AOSetType - Builds an application ordering for a particular implementation.
9 
10   Collective on AO
11 
12   Input Parameters:
13 + ao    - The AO object
14 - method - The name of the AO type
15 
16   Options Database Key:
17 . -ao_type <type> - Sets the AO type; use -help for a list of available types
18 
19   Notes:
20   See "petsc/include/petscao.h" for available AO types (for instance, AOBASIC and AOMEMORYSCALABLE).
21 
22   Level: intermediate
23 
24 .keywords: ao, set, type
25 .seealso: AOGetType(), AOCreate()
26 @*/
27 PetscErrorCode  AOSetType(AO ao, AOType method)
28 {
29   PetscErrorCode (*r)(AO);
30   PetscBool      match;
31   PetscErrorCode ierr;
32 
33   PetscFunctionBegin;
34   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
35   ierr = PetscObjectTypeCompare((PetscObject)ao, method, &match);CHKERRQ(ierr);
36   if (match) PetscFunctionReturn(0);
37 
38   ierr = AORegisterAll();CHKERRQ(ierr);
39   ierr = PetscFunctionListFind(AOList,method,&r);CHKERRQ(ierr);
40   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown AO type: %s", method);
41   if (ao->ops->destroy) {
42     ierr             = (*ao->ops->destroy)(ao);CHKERRQ(ierr);
43     ao->ops->destroy = NULL;
44   }
45 
46   ierr = (*r)(ao);CHKERRQ(ierr);
47   PetscFunctionReturn(0);
48 }
49 
50 /*@C
51   AOGetType - Gets the AO type name (as a string) from the AO.
52 
53   Not Collective
54 
55   Input Parameter:
56 . ao  - The vector
57 
58   Output Parameter:
59 . type - The AO type name
60 
61   Level: intermediate
62 
63 .keywords: ao, get, type, name
64 .seealso: AOSetType(), AOCreate()
65 @*/
66 PetscErrorCode  AOGetType(AO ao, AOType *type)
67 {
68   PetscErrorCode ierr;
69 
70   PetscFunctionBegin;
71   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
72   PetscValidPointer(type,2);
73   ierr = AORegisterAll();CHKERRQ(ierr);
74   *type = ((PetscObject)ao)->type_name;
75   PetscFunctionReturn(0);
76 }
77 
78 
79 /*--------------------------------------------------------------------------------------------------------------------*/
80 
81 /*@C
82   AORegister - Register  an application ordering method
83 
84     Not Collective
85 
86    Input Parameters:
87 +   sname - the name of the AO scheme
88 -   function - the create routine for the application ordering method
89 
90   Level: advanced
91 
92 .seealso:   AOCreate(), AORegisterAll(), AOBASIC, AOADVANCED, AOMAPPING, AOMEMORYSCALABLE
93 
94 @*/
95 PetscErrorCode  AORegister(const char sname[], PetscErrorCode (*function)(AO))
96 {
97   PetscErrorCode ierr;
98 
99   PetscFunctionBegin;
100   ierr = AOInitializePackage();CHKERRQ(ierr);
101   ierr = PetscFunctionListAdd(&AOList,sname,function);CHKERRQ(ierr);
102   PetscFunctionReturn(0);
103 }
104 
105 
106