Actual source code: pmap.c
1: #define PETSCVEC_DLL
2: /*
3: This file contains routines for basic map object implementation.
4: */
6: #include private/vecimpl.h
7: /*@C
8: PetscMapInitialize - given a map where you have set either the global or local
9: size sets up the map so that it may be used.
11: Collective on MPI_Comm
13: Input Parameters:
14: + comm - the MPI communicator
15: - map - pointer to the map
17: Level: intermediate
19: Notes: Typical calling sequence
20: PetscMapInitialize(MPI_Comm,PetscMap *);
21: PetscMapSetBlockSize(PetscMap*,1);
22: PetscMapSetSize(PetscMap*,n) or PetscMapSetLocalSize(PetscMap*,N);
23: PetscMapInitialize(PetscMap*);
24: PetscMapGetSize(PetscMap*,PetscInt *);
26: Unlike regular PETSc objects you work with a pointer to the object instead of
27: the object directly.
29: Fortran Notes:
30: Not available from Fortran
32: .seealso: PetscMapSetLocalSize(), PetscMapSetSize(), PetscMapGetSize(), PetscMapGetLocalSize(), PetscMap,
33: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetBlockSize(), PetscMapSetUp()
35: @*/
38: PetscErrorCode PetscMapInitialize(MPI_Comm comm,PetscMap *map)
39: {
41: map->comm = comm;
42: map->bs = -1;
43: map->n = -1;
44: map->N = -1;
45: map->range = 0;
46: map->rstart = 0;
47: map->rend = 0;
48: return(0);
49: }
51: /*@C
52: PetscMapSetUp - given a map where you have set either the global or local
53: size sets up the map so that it may be used.
55: Collective on MPI_Comm
57: Input Parameters:
58: . map - pointer to the map
60: Level: intermediate
62: Notes: Typical calling sequence
63: PetscMapInitialize(MPI_Comm,PetscMap *);
64: PetscMapSetBlockSize(PetscMap*,1);
65: PetscMapSetSize(PetscMap*,n) or PetscMapSetLocalSize(PetscMap*,N);
66: PetscMapInitialize(PetscMap*);
67: PetscMapGetSize(PetscMap*,PetscInt *);
69: Unlike regular PETSc objects you work with a pointer to the object instead of
70: the object directly.
72: Fortran Notes:
73: Not available from Fortran
75: .seealso: PetscMapSetLocalSize(), PetscMapSetSize(), PetscMapGetSize(), PetscMapGetLocalSize(), PetscMap,
76: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetBlockSize(), PetscMapInitialize()
78: @*/
81: PetscErrorCode PetscMapSetUp(PetscMap *map)
82: {
83: PetscMPIInt rank,size;
84: PetscInt p;
88: MPI_Comm_size(map->comm, &size);
89: MPI_Comm_rank(map->comm, &rank);
90: if (map->bs <=0) {SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"BlockSize not yet set");}
91: if (map->n > 0) map->n = map->n/map->bs;
92: if (map->N > 0) map->N = map->N/map->bs;
93: PetscSplitOwnership(map->comm,&map->n,&map->N);
94: map->n = map->n*map->bs;
95: map->N = map->N*map->bs;
96: if (!map->range) {
97: PetscMalloc((size+1)*sizeof(PetscInt), &map->range);
98: }
99: MPI_Allgather(&map->n, 1, MPIU_INT, map->range+1, 1, MPIU_INT, map->comm);
101: map->range[0] = 0;
102: for(p = 2; p <= size; p++) {
103: map->range[p] += map->range[p-1];
104: }
106: map->rstart = map->range[rank];
107: map->rend = map->range[rank+1];
108: return(0);
109: }
113: PetscErrorCode PetscMapCopy(MPI_Comm comm,PetscMap *in,PetscMap *out)
114: {
115: PetscMPIInt size;
117: PetscInt *range = out->range;
120: MPI_Comm_size(comm,&size);
121: PetscMemcpy(out,in,sizeof(PetscMap));
122: if (!range) {
123: PetscMalloc((size+1)*sizeof(PetscInt),&out->range);
124: } else {
125: out->range = range;
126: }
127: PetscMemcpy(out->range,in->range,(size+1)*sizeof(PetscInt));
128: return(0);
129: }
131: /*@C
132: PetscMapSetLocalSize - Sets the local size for a PetscMap object.
134: Collective on PetscMap
136: Input Parameters:
137: + map - pointer to the map
138: - n - the local size
140: Level: intermediate
142: Notes:
143: Call this after the call to PetscMapInitialize()
145: Unlike regular PETSc objects you work with a pointer to the object instead of
146: the object directly.
148: Fortran Notes:
149: Not available from Fortran
151: .seealso: PetscMapInitialize(), PetscMapSetSize(), PetscMapGetSize(), PetscMapGetLocalSize(), PetscMapSetUp()
152: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetBlockSize()
154: @*/
157: PetscErrorCode PetscMapSetLocalSize(PetscMap *map,PetscInt n)
158: {
160: map->n = n;
161: return(0);
162: }
164: /*@C
165: PetscMapGetLocalSize - Gets the local size for a PetscMap object.
167: Not Collective
169: Input Parameters:
170: . map - pointer to the map
172: Output Parameters:
173: . n - the local size
175: Level: intermediate
177: Notes:
178: Call this after the call to PetscMapSetUp()
180: Unlike regular PETSc objects you work with a pointer to the object instead of
181: the object directly.
183: Fortran Notes:
184: Not available from Fortran
186: .seealso: PetscMapInitialize(), PetscMapSetSize(), PetscMapGetSize(), PetscMapGetLocalSize(), PetscMapSetUp()
187: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetBlockSize()
189: @*/
192: PetscErrorCode PetscMapGetLocalSize(PetscMap *map,PetscInt *n)
193: {
195: *n = map->n;
196: return(0);
197: }
199: /*@C
200: PetscMapSetSize - Sets the global size for a PetscMap object.
202: Collective on PetscMap
204: Input Parameters:
205: + map - pointer to the map
206: - n - the global size
208: Level: intermediate
210: Notes:
211: Call this after the call to PetscMapInitialize()
213: Unlike regular PETSc objects you work with a pointer to the object instead of
214: the object directly.
216: Fortran Notes:
217: Not available from Fortran
219: .seealso: PetscMapInitialize(), PetscMapSetLocalSize(), PetscMapGetLocalSize(), PetscMapGetSize(), PetscMapSetUp()
220: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetBlockSize()
222: @*/
225: PetscErrorCode PetscMapSetSize(PetscMap *map,PetscInt n)
226: {
228: map->N = n;
229: return(0);
230: }
232: /*@C
233: PetscMapGetSize - Gets the global size for a PetscMap object.
235: Not Collective
237: Input Parameters:
238: . map - pointer to the map
240: Output Parameters:
241: . n - the global size
243: Level: intermediate
245: Notes:
246: Call this after the call to PetscMapSetUp()
248: Unlike regular PETSc objects you work with a pointer to the object instead of
249: the object directly.
251: Fortran Notes:
252: Not available from Fortran
254: .seealso: PetscMapInitialize(), PetscMapSetLocalSize(), PetscMapGetLocalSize(), PetscMapSetSize(), PetscMapSetUp()
255: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetBlockSize()
257: @*/
260: PetscErrorCode PetscMapGetSize(PetscMap *map,PetscInt *n)
261: {
263: *n = map->N;
264: return(0);
265: }
267: /*@C
268: PetscMapSetBlockSize - Sets the block size for a PetscMap object.
270: Collective on PetscMap
272: Input Parameters:
273: + map - pointer to the map
274: - bs - the size
276: Level: intermediate
278: Notes:
279: Call this after the call to PetscMapInitialize()
281: Unlike regular PETSc objects you work with a pointer to the object instead of
282: the object directly.
284: Fortran Notes:
285: Not available from Fortran
287: .seealso: PetscMapInitialize(), PetscMapSetLocalSize(), PetscMapGetLocalSize(), PetscMapGetBlockSize(),
288: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetSize(), PetscMapGetSize(), PetscMapSetUp()
290: @*/
293: PetscErrorCode PetscMapSetBlockSize(PetscMap *map,PetscInt bs)
294: {
296: map->bs = bs;
297: return(0);
298: }
300: /*@C
301: PetscMapGetBlockSize - Gets the block size for a PetscMap object.
303: Not Collective
305: Input Parameters:
306: . map - pointer to the map
308: Output Parameters:
309: . bs - the size
311: Level: intermediate
313: Notes:
314: Call this after the call to PetscMapSetUp()
316: Unlike regular PETSc objects you work with a pointer to the object instead of
317: the object directly.
319: Fortran Notes:
320: Not available from Fortran
322: .seealso: PetscMapInitialize(), PetscMapSetLocalSize(), PetscMapGetLocalSize(), PetscMapSetSize(), PetscMapSetUp()
323: PetscMapGetLocalRange(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetSize()
325: @*/
328: PetscErrorCode PetscMapGetBlockSize(PetscMap *map,PetscInt *bs)
329: {
331: *bs = map->bs;
332: return(0);
333: }
336: /*@C
337: PetscMapGetLocalRange - gets the range of values owned by this process
339: Not Collective
341: Input Parameters:
342: . map - pointer to the map
344: Output Parameters:
345: + rstart - first index owned by this process
346: - rend - one more than the last index owned by this process
348: Level: intermediate
350: Notes:
351: Call this after the call to PetscMapSetUp()
353: Unlike regular PETSc objects you work with a pointer to the object instead of
354: the object directly.
356: Fortran Notes:
357: Not available from Fortran
359: .seealso: PetscMapInitialize(), PetscMapSetLocalSize(), PetscMapGetLocalSize(), PetscMapSetSize(),
360: PetscMapGetSize(), PetscMapGetGlobalRange(), PetscMapSetBlockSize(), PetscMapGetSize(), PetscMapSetUp()
362: @*/
365: PetscErrorCode PetscMapGetLocalRange(PetscMap *map,PetscInt *rstart,PetscInt *rend)
366: {
368: if (rstart) *rstart = map->rstart;
369: if (rend) *rend = map->rend;
370: return(0);
371: }
373: /*@C
374: PetscMapGetGlobalRange - gets the range of values owned by all processes
376: Not Collective
378: Input Parameters:
379: . map - pointer to the map
381: Output Parameters:
382: . range - start of each processors range of indices (the final entry is one more then the
383: last index on the last process)
385: Level: intermediate
387: Notes:
388: Call this after the call to PetscMapSetUp()
390: Unlike regular PETSc objects you work with a pointer to the object instead of
391: the object directly.
393: Fortran Notes:
394: Not available from Fortran
396: .seealso: PetscMapInitialize(), PetscMapSetLocalSize(), PetscMapGetLocalSize(), PetscMapSetSize(),
397: PetscMapGetSize(), PetscMapGetLocalRange(), PetscMapSetBlockSize(), PetscMapGetSize(), PetscMapSetUp()
399: @*/
402: PetscErrorCode PetscMapGetGlobalRange(PetscMap *map,const PetscInt *range[])
403: {
405: *range = map->range;
406: return(0);
407: }