xref: /petsc/src/vec/is/ao/interface/aoreg.c (revision 2f613bf53f46f9356e00a2ca2bd69453be72fc31)
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 .seealso: AOGetType(), AOCreate()
25 @*/
26 PetscErrorCode  AOSetType(AO ao, AOType method)
27 {
28   PetscErrorCode (*r)(AO);
29   PetscBool      match;
30   PetscErrorCode ierr;
31 
32   PetscFunctionBegin;
33   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
34   ierr = PetscObjectTypeCompare((PetscObject)ao, method, &match);CHKERRQ(ierr);
35   if (match) PetscFunctionReturn(0);
36 
37   ierr = AORegisterAll();CHKERRQ(ierr);
38   ierr = PetscFunctionListFind(AOList,method,&r);CHKERRQ(ierr);
39   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown AO type: %s", method);
40   if (ao->ops->destroy) {
41     ierr             = (*ao->ops->destroy)(ao);CHKERRQ(ierr);
42     ao->ops->destroy = NULL;
43   }
44 
45   ierr = (*r)(ao);CHKERRQ(ierr);
46   PetscFunctionReturn(0);
47 }
48 
49 /*@C
50   AOGetType - Gets the AO type name (as a string) from the AO.
51 
52   Not Collective
53 
54   Input Parameter:
55 . ao  - The vector
56 
57   Output Parameter:
58 . type - The AO type name
59 
60   Level: intermediate
61 
62 .seealso: AOSetType(), AOCreate()
63 @*/
64 PetscErrorCode  AOGetType(AO ao, AOType *type)
65 {
66   PetscErrorCode ierr;
67 
68   PetscFunctionBegin;
69   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
70   PetscValidPointer(type,2);
71   ierr = AORegisterAll();CHKERRQ(ierr);
72   *type = ((PetscObject)ao)->type_name;
73   PetscFunctionReturn(0);
74 }
75 
76 /*--------------------------------------------------------------------------------------------------------------------*/
77 
78 /*@C
79   AORegister - Register  an application ordering method
80 
81     Not Collective
82 
83    Input Parameters:
84 +   sname - the name of the AO scheme
85 -   function - the create routine for the application ordering method
86 
87   Level: advanced
88 
89 .seealso:   AOCreate(), AORegisterAll(), AOBASIC, AOADVANCED, AOMAPPING, AOMEMORYSCALABLE
90 
91 @*/
92 PetscErrorCode  AORegister(const char sname[], PetscErrorCode (*function)(AO))
93 {
94   PetscErrorCode ierr;
95 
96   PetscFunctionBegin;
97   ierr = AOInitializePackage();CHKERRQ(ierr);
98   ierr = PetscFunctionListAdd(&AOList,sname,function);CHKERRQ(ierr);
99   PetscFunctionReturn(0);
100 }
101 
102