Actual source code: partreg.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: partreg.c,v 1.2 2000/01/10 03:54:25 knepley Exp $";
3: #endif
5: #include src/mesh/meshimpl.h
7: PetscFList PartitionList = 0;
8: int PartitionRegisterAllCalled = 0;
9: PetscFList PartitionSerializeList = 0;
10: int PartitionSerializeRegisterAllCalled = 0;
12: /*@C
13: PartitionSetType - Sets the creation method for the partition.
15: Collective on Partition
17: Input Parameters:
18: + part - The Partition context
19: - method - A known method
21: Options Database Command:
22: . -part_type <method> - Sets the method; use -help for a list
23: of available methods (for instance, tri2d)
25: Notes:
26: See "petsc/include/mesh.h" for available methods (for instance)
27: . PARTITION_SER_TRIANGULAR_2D_BINARY - Triangular 2D to binary file
29: Normally, it is best to use the PartitionSetFromOptions() command and
30: then set the Partition type from the options database rather than by using
31: this routine. Using the options database provides the user with
32: maximum flexibility in evaluating the many different solvers.
33: The PartitionSetType() routine is provided for those situations
34: where it is necessary to set the application ordering independently of the
35: command line or options database. This might be the case, for example,
36: when the choice of solver changes during the execution of the
37: program, and the user's application is taking responsibility for
38: choosing the appropriate method. In other words, this routine is
39: not for beginners.
41: Level: intermediate
43: .keywords: partition, set, type
44: .seealso PartitionSetSerializeType()
45: @*/
46: int PartitionSetType(Partition part, PartitionType method)
47: {
48: int (*r)(Partition);
49: PetscTruth match;
50: int ierr;
54: PetscTypeCompare((PetscObject) part, method, &match);
55: if (match == PETSC_TRUE) return(0);
57: /* Get the function pointers for the method requested */
58: if (!PartitionRegisterAllCalled) {
59: PartitionRegisterAll(PETSC_NULL);
60: }
61: PetscFListFind(part->comm, PartitionList, method, (void (**)(void)) &r);
62: if (!r) {
63: SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
64: }
66: if (part->ops->destroy) {
67: (*part->ops->destroy)(part);
68: }
69: (*r)(part);
71: PetscObjectChangeTypeName((PetscObject) part, method);
72: return(0);
73: }
75: /*@C
76: PartitionGetType - Gets the Partition method type and name (as a string).
78: Not collective
80: Input Parameter:
81: . part - The partition
83: Output Parameter:
84: . type - The name of Partition method
86: Level: intermediate
88: .keywords: partition, get, type
89: .seealso PartitionSetType()
90: @*/
91: int PartitionGetType(Partition part, PartitionType *type)
92: {
98: if (!PartitionRegisterAllCalled) {
99: PartitionRegisterAll(PETSC_NULL);
100: }
101: *type = part->type_name;
102: return(0);
103: }
105: /*@C
106: PartitionSetSerializeType - Sets the serialization method for the part.
108: Collective on Partition
110: Input Parameters:
111: + part - The Partition context
112: - method - A known method
114: Options Database Command:
115: . -part_serialize_type <method> - Sets the method; use -help for a list
116: of available methods (for instance, tri2d_binary)
118: Notes:
119: See "petsc/include/mesh.h" for available methods (for instance)
120: . PARTITION_SER_TRIANGULAR_2D_BINARY - Triangular 2D mesh partition to binary file
122: Normally, it is best to use the PartitionSetFromOptions() command and
123: then set the Partition type from the options database rather than by using
124: this routine. Using the options database provides the user with
125: maximum flexibility in evaluating the many different solvers.
126: The PartitionSetSerializeType() routine is provided for those situations
127: where it is necessary to set the application ordering independently of the
128: command line or options database. This might be the case, for example,
129: when the choice of solver changes during the execution of the
130: program, and the user's application is taking responsibility for
131: choosing the appropriate method. In other words, this routine is
132: not for beginners.
134: Level: intermediate
136: .keywords: partition, set, type, serialization
137: .seealso PartitionSetType()
138: @*/
139: int PartitionSetSerializeType(Partition part, PartitionSerializeType method)
140: {
141: int (*r)(MPI_Comm, Partition *, PetscViewer, PetscTruth);
142: PetscTruth match;
143: int ierr;
147: PetscSerializeCompare((PetscObject) part, method, &match);
148: if (match == PETSC_TRUE) return(0);
150: /* Get the function pointers for the method requested but do not call */
151: if (!PartitionSerializeRegisterAllCalled) {
152: PartitionSerializeRegisterAll(PETSC_NULL);
153: }
154: PetscFListFind(part->comm, PartitionSerializeList, method, (void (**)(void)) &r);
155: if (!r) {
156: SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
157: }
159: PetscObjectChangeSerializeName((PetscObject) part, method);
160: return(0);
161: }
163: /*-------------------------------------------------------------------------------------------------------------------*/
164: /*MC
165: PartitionRegister - Adds a creation method to the partition package.
167: Synopsis:
169: PartitionRegister(char *name, char *path, char *func_name, int (*create_func)(Partition))
171: Not Collective
173: Input Parameters:
174: + name - The name of a new user-defined creation routine
175: . path - The path (either absolute or relative) of the library containing this routine
176: . func_name - The name of routine to create method context
177: - create_func - The creation routine itself
179: Notes:
180: PartitionRegister() may be called multiple times to add several user-defined meshes.
182: If dynamic libraries are used, then the fourth input argument (create_func) is ignored.
184: Sample usage:
185: .vb
186: PartitionRegister("my_part", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyFunc", MyFunc);
187: .ve
189: Then, your mesh type can be chosen with the procedural interface via
190: $ PartitionSetType(vec, "my_part")
191: or at runtime via the option
192: $ -part_type my_part
194: Level: advanced
196: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
198: .keywords: partition, register
199: .seealso: PartitionRegisterAll(), PartitionRegisterDestroy()
200: M*/
201: int PartitionRegister_Private(const char sname[], const char path[], const char name[], int (*function)(Partition))
202: {
203: char fullname[256];
204: int ierr;
207: PetscStrcpy(fullname, path);
208: PetscStrcat(fullname, ":");
209: PetscStrcat(fullname, name);
210: PetscFListAdd(&PartitionList, sname, fullname, (void (*)(void)) function);
211: return(0);
212: }
214: /*MC
215: PartitionSerializeRegister - Adds a serialization method to the partition package.
217: Synopsis:
219: PartitionSerializeRegister(char *serialize_name, char *path, char *serialize_func_name,
220: int (*serialize_func)(MPI_Comm, Partition *, PetscViewer, PetscTruth))
222: Not Collective
224: Input Parameters:
225: + serialize_name - The name of a new user-defined serialization routine
226: . path - The path (either absolute or relative) of the library containing this routine
227: . serialize_func_name - The name of routine to create method context
228: - serialize_func - The serialization routine itself
230: Notes:
231: PartitionSerializeRegister() may be called multiple times to add several user-defined partitioners.
233: If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
235: Sample usage:
236: .vb
237: PartitionSerializeRegister("my_store", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyStoreFunc", MyStoreFunc);
238: .ve
240: Then, your serialization can be chosen with the procedural interface via
241: $ PartitionSetSerializeType(vec, "my_store")
242: or at runtime via the option
243: $ -part_serialize_type my_store
245: Level: advanced
247: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
249: .keywords: partition, register
250: .seealso: PartitionSerializeRegisterAll(), PartitionSerializeRegisterDestroy()
251: M*/
252: int PartitionSerializeRegister_Private(const char sname[], const char path[], const char name[],
253: int (*function)(Mesh, Partition *, PetscViewer, PetscTruth))
254: {
255: char fullname[256];
256: int ierr;
259: PetscStrcpy(fullname, path);
260: PetscStrcat(fullname, ":");
261: PetscStrcat(fullname, name);
262: PetscFListAdd(&PartitionSerializeList, sname, fullname, (void (*)(void)) function);
263: return(0);
264: }
266: /*-------------------------------------------------------------------------------------------------------------------*/
267: /*@C
268: PartitionRegisterDestroy - Frees the list of creation routines for
269: partitions that were registered by FListAdd().
271: Not collective
273: Level: advanced
275: .keywords: partition, register, destroy
276: .seealso: PartitionRegisterAll(), PartitionSerializeRegisterDestroy()
277: @*/
278: int PartitionRegisterDestroy()
279: {
283: if (PartitionList) {
284: PetscFListDestroy(&PartitionList);
285: PartitionList = PETSC_NULL;
286: }
287: PartitionRegisterAllCalled = 0;
288: return(0);
289: }
291: /*@C
292: PartitionSerializeRegisterDestroy - Frees the list of serialization routines for
293: partitions that were registered by FListAdd().
295: Not collective
297: Level: advanced
299: .keywords: partition, serialization, register, destroy
300: .seealso: PartitionSerializeRegisterAll(), PartitionRegisterDestroy()
301: @*/
302: int PartitionSerializeRegisterDestroy()
303: {
307: if (PartitionSerializeList) {
308: PetscFListDestroy(&PartitionSerializeList);
309: PartitionSerializeList = PETSC_NULL;
310: }
311: PartitionSerializeRegisterAllCalled = 0;
312: return(0);
313: }