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: #undef __FUNCT__
17: /*@
18: PartitionSetUp - Set up any required internal data structures for a Partition.
20: Collective on Partition
22: Input Parameter:
23: . part - The part
25: Level: beginner
27: .keywords: Partition, setup
28: .seealso: PartitionDestroy()
29: @*/
30: int PartitionSetUp(Partition part)
31: {
36: if (part->setupcalled) return(0);
37: if (part->ops->setup) {
38: (*part->ops->setup)(part);
39: }
40: return(0);
41: }
43: #undef __FUNCT__
45: /*
46: PartitionSetTypeFromOptions - Sets the type of partitioning from user options.
48: Collective on Partition
50: Input Parameter:
51: . part - The partition
53: Level: intermediate
55: .keywords: Partition, set, options, database, type
56: .seealso: PartitionSetFromOptions(), PartitionSetType()
57: */
58: static int PartitionSetTypeFromOptions(Partition part)
59: {
60: PetscTruth opt;
61: char *defaultType;
62: char typeName[256];
63: int dim;
64: int ierr;
67: PartitionGetDimension(part, &dim);
68: if (part->type_name != PETSC_NULL) {
69: defaultType = part->type_name;
70: } else {
71: switch(dim)
72: {
73: case 2:
74: defaultType = PARTITION_TRIANGULAR_2D;
75: break;
76: default:
77: SETERRQ1(PETSC_ERR_SUP, "Partition dimension %d is not supported", dim);
78: }
79: }
81: if (!PartitionRegisterAllCalled) {
82: PartitionRegisterAll(PETSC_NULL);
83: }
84: PetscOptionsList("-part_type", "Partition method"," PartitionSetType", PartitionList, defaultType, typeName, 256, &opt);
85:
86: if (opt == PETSC_TRUE) {
87: PartitionSetType(part, typeName);
88: } else if (part->type_name == PETSC_NULL) {
89: PartitionSetType(part, defaultType);
90: }
91: return(0);
92: }
94: #undef __FUNCT__
96: /*@
97: PartitionSetFromOptions - Sets various Partition parameters from user options.
99: Collective on Partition
101: Input Parameter:
102: . part - The partition
104: Notes: To see all options, run your program with the -help option, or consult the users manual.
106: Level: intermediate
108: .keywords: Partition, set, options, database
109: .seealso: PartitionPrintHelp(), PartitionSetOptionsPrefix()
110: @*/
111: int PartitionSetFromOptions(Partition part)
112: {
113: PetscTruth opt;
114: int ierr;
118: PetscOptionsBegin(part->comm, part->prefix, "Partition options", "Partition");
120: /* Handle generic part options */
121: PetscOptionsHasName(PETSC_NULL, "-help", &opt);
122: if (opt == PETSC_TRUE) {
123: PartitionPrintHelp(part);
124: }
126: /* Handle part type options */
127: PartitionSetTypeFromOptions(part);
129: /* Handle specific part options */
130: if (part->ops->setfromoptions != PETSC_NULL) {
131: (*part->ops->setfromoptions)(part);
132: }
134: PetscOptionsEnd();
136: /* Handle subobject options */
138: return(0);
139: }
141: #undef __FUNCT__
143: /*@
144: PartitionView - Views a partition object.
146: Collective on Partition
148: Input Parameters:
149: + part - The partition
150: - viewer - The viewer with which to view the partition
152: Level: beginner
154: .keywords: partition, view
155: .seealso: PartitionDestroy(), PetscViewerDrawOpen(), PetscViewerOpenASCII()
156: @*/
157: int PartitionView(Partition part, PetscViewer viewer)
158: {
163: if (!viewer) {
164: viewer = PETSC_VIEWER_STDOUT_SELF;
165: } else {
167: }
168: (*part->ops->view)(part, viewer);
169: return(0);
170: }
172: #undef __FUNCT__
174: /*@
175: PartitionCopy - Copies all the data from one part to another.
177: Collective on Partition
179: Input Parameter:
180: . part - The partition
182: Output Parameter:
183: . newpart - The identical new partition
185: Level: beginner
187: .keywords: Partition, copy
188: .seealso: PartitionDuplicate()
189: @*/
190: int PartitionCopy(Partition part, Partition newpart)
191: {
198: if (!part->ops->copy) {
199: SETERRQ(PETSC_ERR_SUP, "Not supported by this Partition object");
200: }
201: (*part->ops->copy)(part, newpart);
202: return(0);
203: }
205: #undef __FUNCT__
207: /*@
208: PartitionDuplicate - Duplicates the Partition.
210: Collective on Partition
212: Input Parameter:
213: . part - The partition
215: Output Parameter:
216: . newpart - The duplicate partition
218: Level: beginner
220: .keywords: part, duplicate, copy
221: .seealso: PartitionCopy()
222: @*/
223: int PartitionDuplicate(Partition part, Partition *newpart)
224: {
230: if (!part->ops->duplicate) {
231: SETERRQ(PETSC_ERR_SUP, "Not supported by this Partition object");
232: }
233: (*part->ops->duplicate)(part, newpart);
234: return(0);
235: }
237: #undef __FUNCT__
239: /*@
240: PartitionDestroy - Destroys a partition object.
242: Collective on Partition
244: Input Parameter:
245: . part - The partition
247: Level: beginner
249: .keywords: partition, destroy
250: .seealso: PartitionCreate()
251: @*/
252: int PartitionDestroy(Partition part)
253: {
258: if (--part->refct > 0) return(0);
259: (*part->ops->destroy)(part);
260: PetscLogObjectDestroy(part);
261: PetscHeaderDestroy(part);
262: return(0);
263: }
265: #undef __FUNCT__
267: /*@C
268: PartitionSetOptionsPrefix - Sets the prefix used for searching for all Partition options in the database.
270: Not collective
272: Input Parameters:
273: + part - The part
274: - prefix - The prefix to prepend to all option names
276: Notes:
277: A hyphen (-) must NOT be given at the beginning of the prefix name.
278: The first character of all runtime options is AUTOMATICALLY the hyphen.
280: Level: intermediate
282: .keywords: Partition, set, options, prefix, database
283: .seealso: PartitionGetOptionsPrefix(), PartitionAppendOptionsPrefix(), PartitionSetFromOptions()
284: @*/
285: int PartitionSetOptionsPrefix(Partition part, char *prefix)
286: {
291: PetscObjectSetOptionsPrefix((PetscObject) part, prefix);
292: return(0);
293: }
295: #undef __FUNCT__
297: /*@C
298: PartitionAppendOptionsPrefix - Appends to the prefix used for searching for all Partition options in the database.
300: Not collective
302: Input Parameters:
303: + part - The partition
304: - prefix - The prefix to prepend to all option names
306: Notes:
307: A hyphen (-) must NOT be given at the beginning of the prefix name.
308: The first character of all runtime options is AUTOMATICALLY the hyphen.
310: Level: intermediate
312: .keywords: Partition, append, options, prefix, database
313: .seealso: PartitionGetOptionsPrefix(), PartitionSetOptionsPrefix(), PartitionSetFromOptions()
314: @*/
315: int PartitionAppendOptionsPrefix(Partition part, char *prefix)
316: {
318:
321: PetscObjectAppendOptionsPrefix((PetscObject) part, prefix);
322: return(0);
323: }
325: #undef __FUNCT__
327: /*@
328: PartitionGetOptionsPrefix - Returns the prefix used for searching for all Partition options in the database.
330: Input Parameter:
331: . part - The partition
333: Output Parameter:
334: . prefix - A pointer to the prefix string used
336: Level: intermediate
338: .keywords: Partition, get, options, prefix, database
339: .seealso: PartitionSetOptionsPrefix(), PartitionSetOptionsPrefix(), PartitionSetFromOptions()
340: @*/
341: int PartitionGetOptionsPrefix(Partition part, char **prefix)
342: {
347: PetscObjectGetOptionsPrefix((PetscObject) part, prefix);
348: return(0);
349: }
351: #undef __FUNCT__
353: /*@
354: PartitionPrintHelp - Prints all options for the Partition.
356: Input Parameter:
357: . part - The partition
359: Options Database Keys:
360: $ -help, -h
362: Level: intermediate
364: .keywords: part, help
365: .seealso: PartitionSetFromOptions()
366: @*/
367: int PartitionPrintHelp(Partition part)
368: {
369: char p[64];
370: int ierr;
375: PetscStrcpy(p, "-");
376: if (part->prefix != PETSC_NULL) {
377: PetscStrcat(p, part->prefix);
378: }
380: (*PetscHelpPrintf)(part->comm, "Partition options ------------------------------------------------n");
381: (*PetscHelpPrintf)(part->comm," %spartition_type <typename> : Sets the partition typen", p);
382: return(0);
383: }
385: /*------------------------------------------- Partition-Specific Operations ------------------------------------------*/
386: #undef __FUNCT__
388: /*@C
389: PartitionGhostNodeExchange - This functions transfers data between local and ghost storage based on the node ordering.
391: Collective on Partition
393: Input Parameters:
394: + part - The partition
395: . addv - The insert mode, INSERT_VALUES or ADD_VALUES
396: - mode - The direction of the transfer, SCATTER_FORWARD or SCATTER_REVERSE
398: Output Paramters:
399: + locVars - The local variable array
400: - ghostVars - The ghost variables
402: Note:
403: The data in ghostVars is assumed contiguous and implicitly indexed by the order of
404: ghostProcs and ghostIndices. The SCATTER_FORWARD mode will take the requested data
405: from locVars and copy it to ghostVars in the order specified by ghostIndices. The
406: SCATTER_REVERSE mode will take data from ghostVars and copy it to locVars.
408: Level: advanced
410: .keywords: ghost, exchange, grid
411: .seealso: GridGhostExchange(), GridGlobalToLocal(), GridLocalToGlobal()
412: @*/
413: int PartitionGhostNodeExchange(Partition part, InsertMode addv, ScatterMode mode, int *locVars, int *ghostVars)
414: {
418: if (part->numProcs > 1) {
419: if (part->ops->ghostnodeexchange == PETSC_NULL) {
420: SETERRQ(PETSC_ERR_SUP, "Not implemented for this partition type");
421: }
422: (*part->ops->ghostnodeexchange)(part, addv, mode, locVars, ghostVars);
423: }
424: return(0);
425: }