Actual source code: map.c
1: #define PETSCVEC_DLL
2: /*
3: Provides the interface functions for all map operations.
4: These are the map functions the user calls.
5: */
6: #include vecimpl.h
8: /* Logging support */
9: PetscCookie MAP_COOKIE = 0;
13: /*
14: PetscMapSetTypeFromOptions_Private - Sets the type of map from user options. Defaults to a PETSc sequential map on one
15: processor and a PETSc MPI map on more than one processor.
17: Collective on PetscMap
19: Input Parameter:
20: . map - The map
22: Level: intermediate
24: .keywords: PetscMap, set, options, database, type
25: .seealso: PetscMapSetFromOptions(), PetscMapSetType()
26: */
27: static PetscErrorCode PetscMapSetTypeFromOptions_Private(PetscMap map)
28: {
29: PetscTruth opt;
30: const char *defaultType;
31: char typeName[256];
32: PetscMPIInt size;
36: if (map->type_name) {
37: defaultType = map->type_name;
38: } else {
39: MPI_Comm_size(map->comm, &size);
40: if (size > 1) {
41: defaultType = MAP_MPI;
42: } else {
43: defaultType = MAP_MPI;
44: }
45: }
47: if (!PetscMapRegisterAllCalled) {
48: PetscMapRegisterAll(PETSC_NULL);
49: }
50: PetscOptionsList("-map_type", "PetscMap type"," PetscMapSetType", PetscMapList, defaultType, typeName, 256, &opt);
51:
52: if (opt) {
53: PetscMapSetType(map, typeName);
54: } else {
55: PetscMapSetType(map, defaultType);
56: }
57: return(0);
58: }
62: /*@C
63: PetscMapSetFromOptions - Configures the map from the options database.
65: Collective on PetscMap
67: Input Parameter:
68: . map - The map
70: Notes: To see all options, run your program with the -help option, or consult the users manual.
71: Must be called after PetscMapCreate() but before the map is used.
73: Level: intermediate
75: Concepts: maptors^setting options
76: Concepts: maptors^setting type
78: .keywords: PetscMap, set, options, database
79: .seealso: PetscMapCreate(), PetscMapPrintHelp(), PetscMaphSetOptionsPrefix()
80: @*/
81: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapSetFromOptions(PetscMap map)
82: {
83: PetscTruth opt;
89: PetscOptionsBegin(map->comm, map->prefix, "PetscMap options", "PetscMap");
91: /* Handle generic maptor options */
92: PetscOptionsHasName(PETSC_NULL, "-help", &opt);
93: if (opt) {
94: PetscMapPrintHelp(map);
95: }
97: /* Handle map type options */
98: PetscMapSetTypeFromOptions_Private(map);
100: /* Handle specific maptor options */
101: if (map->ops->setfromoptions) {
102: (*map->ops->setfromoptions)(map);
103: }
105: PetscOptionsEnd();
107: return(0);
108: }
112: /*@
113: PetscMapPrintHelp - Prints all options for the PetscMap.
115: Input Parameter:
116: . map - The map
118: Options Database Keys:
119: $ -help, -h
121: Level: intermediate
123: .keywords: PetscMap, help
124: .seealso: PetscMapSetFromOptions()
125: @*/
126: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapPrintHelp(PetscMap map)
127: {
128: char p[64];
134: PetscStrcpy(p, "-");
135: if (map->prefix) {
136: PetscStrcat(p, map->prefix);
137: }
139: (*PetscHelpPrintf)(map->comm, "PetscMap options ------------------------------------------------\n");
140: (*PetscHelpPrintf)(map->comm," %smap_type <typename> : Sets the map type\n", p);
141: return(0);
142: }
146: /*@C
147: PetscMapDestroy - Destroys a map object.
149: Not Collective
151: Input Parameter:
152: . m - the map object
154: Level: developer
156: .seealso: PetscMapCreateMPI()
158: @*/
159: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapDestroy(PetscMap map)
160: {
165: if (--map->refct > 0) return(0);
166: if (map->range) {
167: PetscFree(map->range);
168: }
169: if (map->ops->destroy) {
170: (*map->ops->destroy)(map);
171: }
172: PetscHeaderDestroy(map);
173: return(0);
174: }
178: /*@C
179: PetscMapSetOptionsPrefix - Sets the prefix used for searching for all
180: PetscMap options in the database.
182: Collective on PetscMap
184: Input Parameter:
185: + map - the PetscMap context
186: - prefix - the prefix to prepend to all option names
188: Notes:
189: A hyphen (-) must NOT be given at the beginning of the prefix name.
190: The first character of all runtime options is AUTOMATICALLY the hyphen.
192: Level: advanced
194: .keywords: PetscMap, set, options, prefix, database
196: .seealso: PetscMapSetFromOptions()
197: @*/
198: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapSetOptionsPrefix(PetscMap map,const char prefix[])
199: {
204: PetscObjectSetOptionsPrefix((PetscObject)map,prefix);
205: return(0);
206: }
210: /*@C
211: PetscMapAppendOptionsPrefix - Appends to the prefix used for searching for all
212: PetscMap options in the database.
214: Collective on PetscMap
216: Input Parameters:
217: + map - the PetscMap context
218: - prefix - the prefix to prepend to all option names
220: Notes:
221: A hyphen (-) must NOT be given at the beginning of the prefix name.
222: The first character of all runtime options is AUTOMATICALLY the hyphen.
224: Level: advanced
226: .keywords: PetscMap, append, options, prefix, database
228: .seealso: PetscMapGetOptionsPrefix()
229: @*/
230: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapAppendOptionsPrefix(PetscMap map,const char prefix[])
231: {
233:
236: PetscObjectAppendOptionsPrefix((PetscObject)map,prefix);
237: return(0);
238: }
242: /*@C
243: PetscMapGetOptionsPrefix - Sets the prefix used for searching for all
244: PetscMap options in the database.
246: Not Collective
248: Input Parameter:
249: . map - the PetscMap context
251: Output Parameter:
252: . prefix - pointer to the prefix string used
254: Notes: On the fortran side, the user should pass in a string 'prefix' of
255: sufficient length to hold the prefix.
257: Level: advanced
259: .keywords: PetscMap, get, options, prefix, database
261: .seealso: PetscMapAppendOptionsPrefix()
262: @*/
263: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapGetOptionsPrefix(PetscMap map,const char *prefix[])
264: {
269: PetscObjectGetOptionsPrefix((PetscObject)map,prefix);
270: return(0);
271: }
275: /*@
276: PetscMapSetUp - Sets up the internal map data structures for the later use.
278: Collective on PetscMap
280: Input Parameters:
281: . map - the PetscMap context
283: Notes:
284: For basic use of the PetscMap classes the user need not explicitly call
285: PetscMapSetUp(), since these actions will happen automatically.
287: Level: advanced
289: .keywords: PetscMap, setup
291: .seealso: PetscMapCreate(), PetscMapDestroy()
292: @*/
293: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapSetUp(PetscMap map)
294: {
297: return(0);
298: }
302: /*@C
303: PetscMapView - Visualizes a map object.
305: Collective on PetscMap
307: Input Parameters:
308: + map - the map
309: - viewer - visualization context
311: Notes:
312: The available visualization contexts include
313: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
314: . PETSC_VIEWER_STDOUT_WORLD - synchronized standard
315: output where only the first processor opens
316: the file. All other processors send their
317: data to the first processor to print.
318: - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure
320: Level: beginner
322: .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(),
323: PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscMapLoad()
324: @*/
325: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapView(PetscMap map,PetscViewer viewer)
326: {
327: PetscErrorCode ierr;
328: PetscInt size;
329: PetscTruth iascii;
330: const char *cstr;
331: PetscViewerFormat format;
336: if (!viewer) viewer = PETSC_VIEWER_STDOUT_(map->comm);
340: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
341: if (iascii) {
342: PetscViewerGetFormat(viewer,&format);
343: if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
344: if (map->prefix) {
345: PetscViewerASCIIPrintf(viewer,"PetscMap Object:(%s)\n",map->prefix);
346: } else {
347: PetscViewerASCIIPrintf(viewer,"PetscMap Object:\n");
348: }
349: PetscViewerASCIIPushTab(viewer);
350: PetscMapGetType(map,&cstr);
351: PetscMapGetSize(map,&size);
352: PetscViewerASCIIPrintf(viewer,"type=%s, size=%D\n",cstr,size);
353: }
354: }
355: if (!iascii) {
356: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported",((PetscObject)viewer)->type_name);
357: } else {
358: PetscViewerGetFormat(viewer,&format);
359: if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
360: PetscViewerASCIIPopTab(viewer);
361: }
362: }
363: return(0);
364: }
368: /*@C
369: PetscMapSetLocalSize - Sets the number of elements associated with this processor.
371: Not Collective
373: Input Parameters:
374: + m - the map object
375: - n - the local size
377: Level: developer
379: .seealso: PetscMapSetSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
380: Concepts: PetscMap^local size
381: @*/
382: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapSetLocalSize(PetscMap m,PetscInt n)
383: {
386: m->n = n;
387: return(0);
388: }
392: /*@C
393: PetscMapGetLocalSize - Gets the number of elements associated with this processor.
395: Not Collective
397: Input Parameter:
398: . m - the map object
400: Output Parameter:
401: . n - the local size
403: Level: developer
405: .seealso: PetscMapGetSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
407: Concepts: PetscMap^local size
409: @*/
410: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapGetLocalSize(PetscMap m,PetscInt *n)
411: {
415: *n = m->n;
416: return(0);
417: }
421: /*@C
422: PetscMapSetSize - Sets the total number of elements associated with this map.
424: Not Collective
426: Input Parameters:
427: + m - the map object
428: - N - the global size
430: Level: developer
432: .seealso: PetscMapSetLocalSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
433: Concepts: PetscMap^size
434: @*/
435: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapSetSize(PetscMap m,PetscInt N)
436: {
439: m->N = N;
440: return(0);
441: }
445: /*@C
446: PetscMapGetSize - Gets the total number of elements associated with this map.
448: Not Collective
450: Input Parameter:
451: . m - the map object
453: Output Parameter:
454: . N - the global size
456: Level: developer
458: .seealso: PetscMapGetLocalSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
460: Concepts: PetscMap^size
461: @*/
462: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapGetSize(PetscMap m,PetscInt *N)
463: {
467: *N = m->N;
468: return(0);
469: }
473: /*@C
474: PetscMapGetLocalRange - Gets the local ownership range for this procesor.
476: Not Collective
478: Input Parameter:
479: . m - the map object
481: Output Parameter:
482: + rstart - the first local index, pass in PETSC_NULL if not interested
483: - rend - the last local index + 1, pass in PETSC_NULL if not interested
485: Level: developer
487: .seealso: PetscMapGetLocalSize(), PetscMapGetGlobalRange()
488: @*/
489: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapGetLocalRange(PetscMap m,PetscInt *rstart,PetscInt *rend)
490: {
495: if (rstart) *rstart = m->rstart;
496: if (rend) *rend = m->rend;
497: return(0);
498: }
502: /*@C
503: PetscMapGetGlobalRange - Gets the ownership ranges for all processors.
505: Not Collective
507: Input Parameter:
508: . m - the map object
510: Output Parameter:
511: . range - array of size + 1 where size is the size of the communicator
512: associated with the map. range[rank], range[rank+1] is the
513: range for processor
515: Level: developer
517: .seealso: PetscMapGetSize(), PetscMapGetLocalRange()
519: @*/
520: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapGetGlobalRange(PetscMap m,PetscInt *range[])
521: {
525: *range = m->range;
526: return(0);
527: }