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