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: #undef __FUNCT__
14: /*@C
15: PartitionSetType - Sets the creation method for the partition.
17: Collective on Partition
19: Input Parameters:
20: + part - The Partition context
21: - method - A known method
23: Options Database Command:
24: . -part_type <method> - Sets the method; use -help for a list
25: of available methods (for instance, tri2d)
27: Notes:
28: See "petsc/include/mesh.h" for available methods (for instance)
29: . PARTITION_SER_TRIANGULAR_2D_BINARY - Triangular 2D to binary file
31: Normally, it is best to use the PartitionSetFromOptions() command and
32: then set the Partition type from the options database rather than by using
33: this routine. Using the options database provides the user with
34: maximum flexibility in evaluating the many different solvers.
35: The PartitionSetType() routine is provided for those situations
36: where it is necessary to set the application ordering independently of the
37: command line or options database. This might be the case, for example,
38: when the choice of solver changes during the execution of the
39: program, and the user's application is taking responsibility for
40: choosing the appropriate method. In other words, this routine is
41: not for beginners.
43: Level: intermediate
45: .keywords: partition, set, type
46: .seealso PartitionSetSerializeType()
47: @*/
48: int PartitionSetType(Partition part, PartitionType method)
49: {
50: int (*r)(Partition);
51: PetscTruth match;
52: int ierr;
56: PetscTypeCompare((PetscObject) part, method, &match);
57: if (match == PETSC_TRUE) return(0);
59: /* Get the function pointers for the method requested */
60: if (!PartitionRegisterAllCalled) {
61: PartitionRegisterAll(PETSC_NULL);
62: }
63: PetscFListFind(part->comm, PartitionList, method, (void (**)(void)) &r);
64: if (!r) {
65: SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
66: }
68: if (part->ops->destroy) {
69: (*part->ops->destroy)(part);
70: }
71: (*r)(part);
73: PetscObjectChangeTypeName((PetscObject) part, method);
74: return(0);
75: }
77: #undef __FUNCT__
79: /*@C
80: PartitionGetType - Gets the Partition method type and name (as a string).
82: Not collective
84: Input Parameter:
85: . part - The partition
87: Output Parameter:
88: . type - The name of Partition method
90: Level: intermediate
92: .keywords: partition, get, type
93: .seealso PartitionSetType()
94: @*/
95: int PartitionGetType(Partition part, PartitionType *type)
96: {
102: if (!PartitionRegisterAllCalled) {
103: PartitionRegisterAll(PETSC_NULL);
104: }
105: *type = part->type_name;
106: return(0);
107: }
109: #undef __FUNCT__
111: /*@C
112: PartitionSetSerializeType - Sets the serialization method for the part.
114: Collective on Partition
116: Input Parameters:
117: + part - The Partition context
118: - method - A known method
120: Options Database Command:
121: . -part_serialize_type <method> - Sets the method; use -help for a list
122: of available methods (for instance, tri2d_binary)
124: Notes:
125: See "petsc/include/mesh.h" for available methods (for instance)
126: . PARTITION_SER_TRIANGULAR_2D_BINARY - Triangular 2D mesh partition to binary file
128: Normally, it is best to use the PartitionSetFromOptions() command and
129: then set the Partition type from the options database rather than by using
130: this routine. Using the options database provides the user with
131: maximum flexibility in evaluating the many different solvers.
132: The PartitionSetSerializeType() routine is provided for those situations
133: where it is necessary to set the application ordering independently of the
134: command line or options database. This might be the case, for example,
135: when the choice of solver changes during the execution of the
136: program, and the user's application is taking responsibility for
137: choosing the appropriate method. In other words, this routine is
138: not for beginners.
140: Level: intermediate
142: .keywords: partition, set, type, serialization
143: .seealso PartitionSetType()
144: @*/
145: int PartitionSetSerializeType(Partition part, PartitionSerializeType method)
146: {
147: int (*r)(MPI_Comm, Partition *, PetscViewer, PetscTruth);
148: PetscTruth match;
149: int ierr;
153: PetscSerializeCompare((PetscObject) part, method, &match);
154: if (match == PETSC_TRUE) return(0);
156: /* Get the function pointers for the method requested but do not call */
157: if (!PartitionSerializeRegisterAllCalled) {
158: PartitionSerializeRegisterAll(PETSC_NULL);
159: }
160: PetscFListFind(part->comm, PartitionSerializeList, method, (void (**)(void)) &r);
161: if (!r) {
162: SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
163: }
165: PetscObjectChangeSerializeName((PetscObject) part, method);
166: return(0);
167: }
169: /*-------------------------------------------------------------------------------------------------------------------*/
170: /*MC
171: PartitionRegister - Adds a creation method to the partition package.
173: Synopsis:
175: PartitionRegister(char *name, char *path, char *func_name, int (*create_func)(Partition))
177: Not Collective
179: Input Parameters:
180: + name - The name of a new user-defined creation routine
181: . path - The path (either absolute or relative) of the library containing this routine
182: . func_name - The name of routine to create method context
183: - create_func - The creation routine itself
185: Notes:
186: PartitionRegister() may be called multiple times to add several user-defined meshes.
188: If dynamic libraries are used, then the fourth input argument (create_func) is ignored.
190: Sample usage:
191: .vb
192: PartitionRegister("my_part", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyFunc", MyFunc);
193: .ve
195: Then, your mesh type can be chosen with the procedural interface via
196: $ PartitionSetType(vec, "my_part")
197: or at runtime via the option
198: $ -part_type my_part
200: Level: advanced
202: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
204: .keywords: partition, register
205: .seealso: PartitionRegisterAll(), PartitionRegisterDestroy()
206: M*/
207: #undef __FUNCT__
209: int PartitionRegister_Private(const char sname[], const char path[], const char name[], int (*function)(Partition))
210: {
211: char fullname[256];
212: int ierr;
215: PetscStrcpy(fullname, path);
216: PetscStrcat(fullname, ":");
217: PetscStrcat(fullname, name);
218: PetscFListAdd(&PartitionList, sname, fullname, (void (*)(void)) function);
219: return(0);
220: }
222: /*MC
223: PartitionSerializeRegister - Adds a serialization method to the partition package.
225: Synopsis:
227: PartitionSerializeRegister(char *serialize_name, char *path, char *serialize_func_name,
228: int (*serialize_func)(MPI_Comm, Partition *, PetscViewer, PetscTruth))
230: Not Collective
232: Input Parameters:
233: + serialize_name - The name of a new user-defined serialization routine
234: . path - The path (either absolute or relative) of the library containing this routine
235: . serialize_func_name - The name of routine to create method context
236: - serialize_func - The serialization routine itself
238: Notes:
239: PartitionSerializeRegister() may be called multiple times to add several user-defined partitioners.
241: If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
243: Sample usage:
244: .vb
245: PartitionSerializeRegister("my_store", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyStoreFunc", MyStoreFunc);
246: .ve
248: Then, your serialization can be chosen with the procedural interface via
249: $ PartitionSetSerializeType(vec, "my_store")
250: or at runtime via the option
251: $ -part_serialize_type my_store
253: Level: advanced
255: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
257: .keywords: partition, register
258: .seealso: PartitionSerializeRegisterAll(), PartitionSerializeRegisterDestroy()
259: M*/
260: #undef __FUNCT__
262: int PartitionSerializeRegister_Private(const char sname[], const char path[], const char name[],
263: int (*function)(Mesh, Partition *, PetscViewer, PetscTruth))
264: {
265: char fullname[256];
266: int ierr;
269: PetscStrcpy(fullname, path);
270: PetscStrcat(fullname, ":");
271: PetscStrcat(fullname, name);
272: PetscFListAdd(&PartitionSerializeList, sname, fullname, (void (*)(void)) function);
273: return(0);
274: }
276: /*-------------------------------------------------------------------------------------------------------------------*/
277: #undef __FUNCT__
279: /*@C
280: PartitionRegisterDestroy - Frees the list of creation routines for
281: partitions that were registered by FListAdd().
283: Not collective
285: Level: advanced
287: .keywords: partition, register, destroy
288: .seealso: PartitionRegisterAll(), PartitionSerializeRegisterDestroy()
289: @*/
290: int PartitionRegisterDestroy()
291: {
295: if (PartitionList) {
296: PetscFListDestroy(&PartitionList);
297: PartitionList = PETSC_NULL;
298: }
299: PartitionRegisterAllCalled = 0;
300: return(0);
301: }
303: #undef __FUNCT__
305: /*@C
306: PartitionSerializeRegisterDestroy - Frees the list of serialization routines for
307: partitions that were registered by FListAdd().
309: Not collective
311: Level: advanced
313: .keywords: partition, serialization, register, destroy
314: .seealso: PartitionSerializeRegisterAll(), PartitionRegisterDestroy()
315: @*/
316: int PartitionSerializeRegisterDestroy()
317: {
321: if (PartitionSerializeList) {
322: PetscFListDestroy(&PartitionSerializeList);
323: PartitionSerializeList = PETSC_NULL;
324: }
325: PartitionSerializeRegisterAllCalled = 0;
326: return(0);
327: }