Actual source code: aoreg.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: aoreg.c,v 1.2 2000/01/10 03:15:40 knepley Exp $";
3: #endif
5: #include src/dm/ao/aoimpl.h
7: PetscFList AOSerializeList = 0;
8: int AOSerializeRegisterAllCalled = 0;
10: /*@C
11: AOSetSerializeType - Sets the serialization method for the application ordering.
13: Collective on AO
15: Input Parameters:
16: + ao - The AO context
17: - method - A known method
19: Options Database Command:
20: . -ao_serialize_type <method> - Sets the method; use -help for a list
21: of available methods (for instance, debug_binary)
23: Notes:
24: See "petsc/include/petscao.h" for available methods (for instance)
25: + AO_SER_DEBUG_BINARY - Debugging ordering to binary file
26: - AO_SER_BASIC_BINARY - Scalable ordering to binary file
28: Normally, it is best to use the AOSetFromOptions() command and
29: then set the AO type from the options database rather than by using
30: this routine. Using the options database provides the user with
31: maximum flexibility in evaluating the many different solvers.
32: The AOSetSerializeType() routine is provided for those situations
33: where it is necessary to set the application ordering independently of the
34: command line or options database. This might be the case, for example,
35: when the choice of solver changes during the execution of the
36: program, and the user's application is taking responsibility for
37: choosing the appropriate method. In other words, this routine is
38: not for beginners.
40: Level: intermediate
42: .keywords: AO, set, type, serialization
43: @*/
44: int AOSetSerializeType(AO ao, AOSerializeType method)
45: {
46: int (*r)(MPI_Comm, AO *, PetscViewer, PetscTruth);
47: PetscTruth match;
48: int ierr;
52: PetscSerializeCompare((PetscObject) ao, method, &match);
53: if (match == PETSC_TRUE) return(0);
55: /* Get the function pointers for the method requested but do not call */
56: if (!AOSerializeRegisterAllCalled) {
57: AOSerializeRegisterAll(PETSC_NULL);
58: }
59: PetscFListFind(ao->comm, AOSerializeList, method, (void (**)(void)) &r);
60: if (!r) {
61: SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
62: }
64: PetscObjectChangeSerializeName((PetscObject) ao, method);
65: return(0);
66: }
68: /*MC
69: AOSerializeRegister - Adds a serialization method to the application ordering package.
71: Synopsis:
73: AOSerializeRegister(char *serialize_name, char *path, char *serialize_func_name,
74: int (*serialize_func)(MPI_Comm, AO *, PetscViewer, PetscTruth))
76: Not Collective
78: Input Parameters:
79: + serialize_name - The name of a new user-defined serialization routine
80: . path - The path (either absolute or relative) of the library containing this routine
81: . serialize_func_name - The name of routine to create method context
82: - serialize_func - The serialization routine itself
84: Notes:
85: AOSerializeRegister() may be called multiple times to add several user-defined solvers.
87: If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
89: Sample usage:
90: .vb
91: AOSerializeRegister("my_store", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyStoreFunc", MyStoreFunc);
92: .ve
94: Then, your serialization can be chosen with the procedural interface via
95: $ AOSetSerializeType(ao, "my_store")
96: or at runtime via the option
97: $ -ao_serialize_type my_store
99: Level: advanced
101: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
103: .keywords: AO, register
105: .seealso: AOSerializeRegisterAll(), AOSerializeRegisterDestroy()
106: M*/
107: int AOSerializeRegister_Private(const char *sname,const char *path,const char *name,int (*function)(MPI_Comm, AO *, PetscViewer, PetscTruth))
108: {
109: char fullname[256];
110: int ierr;
113: PetscStrcpy(fullname, path);
114: PetscStrcat(fullname, ":");
115: PetscStrcat(fullname, name);
116: PetscFListAdd(&AOSerializeList, sname, fullname, (void (*)(void)) function);
117: return(0);
118: }
120: /*-------------------------------------------------------------------------------------------------------------------*/
121: /*@C
122: AOSerializeRegisterDestroy - Frees the list of serialization routines for
123: application orderings that were registered by PetscFListAdd().
125: Not Collective
127: Level: advanced
129: .keywords: AO, application ordering, register, destroy
131: .seealso: AOSerializeRegisterAll(), AORegisterAll()
132: @*/
133: int AOSerializeRegisterDestroy(void)
134: {
138: if (AOSerializeList) {
139: PetscFListDestroy(&AOSerializeList);
140: AOSerializeList = PETSC_NULL;
141: }
142: AOSerializeRegisterAllCalled = 0;
143: return(0);
144: }