xref: /petsc/src/vec/is/ao/interface/aoreg.c (revision 8cc058d9cd56c1ccb3be12a47760ddfc446aaffc)
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(NULL);CHKERRQ(ierr);}
41   ierr = PetscFunctionListFind(PetscObjectComm((PetscObject)ao), AOList, method,PETSC_TRUE,(void (**)(void)) &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(NULL);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 - See AORegisterDynamic()
91 
92   Level: advanced
93 @*/
94 PetscErrorCode  AORegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(AO))
95 {
96   char           fullname[PETSC_MAX_PATH_LEN];
97   PetscErrorCode ierr;
98 
99   PetscFunctionBegin;
100   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
101   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
102   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
103   ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&AOList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr);
104   PetscFunctionReturn(0);
105 }
106 
107 
108 /*--------------------------------------------------------------------------------------------------------------------*/
109 #undef __FUNCT__
110 #define __FUNCT__ "AORegisterDestroy"
111 /*@C
112    AORegisterDestroy - Frees the list of AO methods that were registered by AORegister()/AORegisterDynamic().
113 
114    Not Collective
115 
116    Level: advanced
117 
118 .keywords: AO, register, destroy
119 .seealso: AORegister(), AORegisterAll(), AORegisterDynamic()
120 @*/
121 PetscErrorCode  AORegisterDestroy(void)
122 {
123   PetscErrorCode ierr;
124 
125   PetscFunctionBegin;
126   ierr                = PetscFunctionListDestroy(&AOList);CHKERRQ(ierr);
127   AORegisterAllCalled = PETSC_FALSE;
128   PetscFunctionReturn(0);
129 }
130 
131