Actual source code: part.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: part.c,v 1.6 2000/01/31 17:37:32 knepley Exp $";
3: #endif
5: /*
6: Defines the interface to the partitioning functions
7: */
9: #include src/mesh/meshimpl.h
11: /* Logging support */
12: int PARTITION_COOKIE;
14: /*------------------------------------------------ Generic Operations ------------------------------------------------*/
15: /*@
16: PartitionSetUp - Set up any required internal data structures for a Partition.
18: Collective on Partition
20: Input Parameter:
21: . part - The part
23: Level: beginner
25: .keywords: Partition, setup
26: .seealso: PartitionDestroy()
27: @*/
28: int PartitionSetUp(Partition part)
29: {
34: if (part->setupcalled) return(0);
35: if (part->ops->setup) {
36: (*part->ops->setup)(part);
37: }
38: return(0);
39: }
41: /*
42: PartitionSetTypeFromOptions - Sets the type of partitioning from user options.
44: Collective on Partition
46: Input Parameter:
47: . part - The partition
49: Level: intermediate
51: .keywords: Partition, set, options, database, type
52: .seealso: PartitionSetFromOptions(), PartitionSetType()
53: */
54: static int PartitionSetTypeFromOptions(Partition part)
55: {
56: PetscTruth opt;
57: char *defaultType;
58: char typeName[256];
59: int dim;
60: int ierr;
63: PartitionGetDimension(part, &dim);
64: if (part->type_name != PETSC_NULL) {
65: defaultType = part->type_name;
66: } else {
67: switch(dim)
68: {
69: case 2:
70: defaultType = PARTITION_TRIANGULAR_2D;
71: break;
72: default:
73: SETERRQ1(PETSC_ERR_SUP, "Partition dimension %d is not supported", dim);
74: }
75: }
77: if (!PartitionRegisterAllCalled) {
78: PartitionRegisterAll(PETSC_NULL);
79: }
80: PetscOptionsList("-part_type", "Partition method"," PartitionSetType", PartitionList, defaultType, typeName, 256, &opt);
81:
82: if (opt == PETSC_TRUE) {
83: PartitionSetType(part, typeName);
84: } else if (part->type_name == PETSC_NULL) {
85: PartitionSetType(part, defaultType);
86: }
87: return(0);
88: }
90: /*@
91: PartitionSetFromOptions - Sets various Partition parameters from user options.
93: Collective on Partition
95: Input Parameter:
96: . part - The partition
98: Notes: To see all options, run your program with the -help option, or consult the users manual.
100: Level: intermediate
102: .keywords: Partition, set, options, database
103: .seealso: PartitionPrintHelp(), PartitionSetOptionsPrefix()
104: @*/
105: int PartitionSetFromOptions(Partition part)
106: {
107: PetscTruth opt;
108: int ierr;
112: PetscOptionsBegin(part->comm, part->prefix, "Partition options", "Partition");
114: /* Handle generic part options */
115: PetscOptionsHasName(PETSC_NULL, "-help", &opt);
116: if (opt == PETSC_TRUE) {
117: PartitionPrintHelp(part);
118: }
120: /* Handle part type options */
121: PartitionSetTypeFromOptions(part);
123: /* Handle specific part options */
124: if (part->ops->setfromoptions != PETSC_NULL) {
125: (*part->ops->setfromoptions)(part);
126: }
128: PetscOptionsEnd();
130: /* Handle subobject options */
132: return(0);
133: }
135: /*@
136: PartitionView - Views a partition object.
138: Collective on Partition
140: Input Parameters:
141: + part - The partition
142: - viewer - The viewer with which to view the partition
144: Level: beginner
146: .keywords: partition, view
147: .seealso: PartitionDestroy(), PetscViewerDrawOpen(), PetscViewerOpenASCII()
148: @*/
149: int PartitionView(Partition part, PetscViewer viewer)
150: {
155: if (!viewer) {
156: viewer = PETSC_VIEWER_STDOUT_SELF;
157: } else {
159: }
160: (*part->ops->view)(part, viewer);
161: return(0);
162: }
164: /*@
165: PartitionCopy - Copies all the data from one part to another.
167: Collective on Partition
169: Input Parameter:
170: . part - The partition
172: Output Parameter:
173: . newpart - The identical new partition
175: Level: beginner
177: .keywords: Partition, copy
178: .seealso: PartitionDuplicate()
179: @*/
180: int PartitionCopy(Partition part, Partition newpart)
181: {
188: if (!part->ops->copy) {
189: SETERRQ(PETSC_ERR_SUP, "Not supported by this Partition object");
190: }
191: (*part->ops->copy)(part, newpart);
192: return(0);
193: }
195: /*@
196: PartitionDuplicate - Duplicates the Partition.
198: Collective on Partition
200: Input Parameter:
201: . part - The partition
203: Output Parameter:
204: . newpart - The duplicate partition
206: Level: beginner
208: .keywords: part, duplicate, copy
209: .seealso: PartitionCopy()
210: @*/
211: int PartitionDuplicate(Partition part, Partition *newpart)
212: {
218: if (!part->ops->duplicate) {
219: SETERRQ(PETSC_ERR_SUP, "Not supported by this Partition object");
220: }
221: (*part->ops->duplicate)(part, newpart);
222: return(0);
223: }
225: /*@
226: PartitionDestroy - Destroys a partition object.
228: Collective on Partition
230: Input Parameter:
231: . part - The partition
233: Level: beginner
235: .keywords: partition, destroy
236: .seealso: PartitionCreate()
237: @*/
238: int PartitionDestroy(Partition part)
239: {
244: if (--part->refct > 0) return(0);
245: (*part->ops->destroy)(part);
246: PetscLogObjectDestroy(part);
247: PetscHeaderDestroy(part);
248: return(0);
249: }
251: /*@C
252: PartitionSetOptionsPrefix - Sets the prefix used for searching for all Partition options in the database.
254: Not collective
256: Input Parameters:
257: + part - The part
258: - prefix - The prefix to prepend to all option names
260: Notes:
261: A hyphen (-) must NOT be given at the beginning of the prefix name.
262: The first character of all runtime options is AUTOMATICALLY the hyphen.
264: Level: intermediate
266: .keywords: Partition, set, options, prefix, database
267: .seealso: PartitionGetOptionsPrefix(), PartitionAppendOptionsPrefix(), PartitionSetFromOptions()
268: @*/
269: int PartitionSetOptionsPrefix(Partition part, char *prefix)
270: {
275: PetscObjectSetOptionsPrefix((PetscObject) part, prefix);
276: return(0);
277: }
279: /*@C
280: PartitionAppendOptionsPrefix - Appends to the prefix used for searching for all Partition options in the database.
282: Not collective
284: Input Parameters:
285: + part - The partition
286: - prefix - The prefix to prepend to all option names
288: Notes:
289: A hyphen (-) must NOT be given at the beginning of the prefix name.
290: The first character of all runtime options is AUTOMATICALLY the hyphen.
292: Level: intermediate
294: .keywords: Partition, append, options, prefix, database
295: .seealso: PartitionGetOptionsPrefix(), PartitionSetOptionsPrefix(), PartitionSetFromOptions()
296: @*/
297: int PartitionAppendOptionsPrefix(Partition part, char *prefix)
298: {
300:
303: PetscObjectAppendOptionsPrefix((PetscObject) part, prefix);
304: return(0);
305: }
307: /*@
308: PartitionGetOptionsPrefix - Returns the prefix used for searching for all Partition options in the database.
310: Input Parameter:
311: . part - The partition
313: Output Parameter:
314: . prefix - A pointer to the prefix string used
316: Level: intermediate
318: .keywords: Partition, get, options, prefix, database
319: .seealso: PartitionSetOptionsPrefix(), PartitionSetOptionsPrefix(), PartitionSetFromOptions()
320: @*/
321: int PartitionGetOptionsPrefix(Partition part, char **prefix)
322: {
327: PetscObjectGetOptionsPrefix((PetscObject) part, prefix);
328: return(0);
329: }
331: /*@
332: PartitionPrintHelp - Prints all options for the Partition.
334: Input Parameter:
335: . part - The partition
337: Options Database Keys:
338: $ -help, -h
340: Level: intermediate
342: .keywords: part, help
343: .seealso: PartitionSetFromOptions()
344: @*/
345: int PartitionPrintHelp(Partition part)
346: {
347: char p[64];
348: int ierr;
353: PetscStrcpy(p, "-");
354: if (part->prefix != PETSC_NULL) {
355: PetscStrcat(p, part->prefix);
356: }
358: (*PetscHelpPrintf)(part->comm, "Partition options ------------------------------------------------n");
359: (*PetscHelpPrintf)(part->comm," %spartition_type <typename> : Sets the partition typen", p);
360: return(0);
361: }
363: /*------------------------------------------- Partition-Specific Operations ------------------------------------------*/
364: /*@C
365: PartitionGhostNodeExchange - This functions transfers data between local and ghost storage based on the node ordering.
367: Collective on Partition
369: Input Parameters:
370: + part - The partition
371: . addv - The insert mode, INSERT_VALUES or ADD_VALUES
372: - mode - The direction of the transfer, SCATTER_FORWARD or SCATTER_REVERSE
374: Output Paramters:
375: + locVars - The local variable array
376: - ghostVars - The ghost variables
378: Note:
379: The data in ghostVars is assumed contiguous and implicitly indexed by the order of
380: ghostProcs and ghostIndices. The SCATTER_FORWARD mode will take the requested data
381: from locVars and copy it to ghostVars in the order specified by ghostIndices. The
382: SCATTER_REVERSE mode will take data from ghostVars and copy it to locVars.
384: Level: advanced
386: .keywords: ghost, exchange, grid
387: .seealso: GridGhostExchange(), GridGlobalToLocal(), GridLocalToGlobal()
388: @*/
389: int PartitionGhostNodeExchange(Partition part, InsertMode addv, ScatterMode mode, int *locVars, int *ghostVars)
390: {
394: if (part->numProcs > 1) {
395: if (part->ops->ghostnodeexchange == PETSC_NULL) {
396: SETERRQ(PETSC_ERR_SUP, "Not implemented for this partition type");
397: }
398: (*part->ops->ghostnodeexchange)(part, addv, mode, locVars, ghostVars);
399: }
400: return(0);
401: }