Actual source code: map.c

  1: /*$Id: map.c,v 1.15 2001/07/20 21:18:10 bsmith Exp $*/
  2: /*
  3:      Provides the interface functions for all map operations.
  4:    These are the map functions the user calls.
  5: */
 6:  #include src/vec/vecimpl.h

  8: /* Logging support */
  9: int MAP_COOKIE;

 11: /*
 12:   PetscMapSetTypeFromOptions_Private - Sets the type of map from user options. Defaults to a PETSc sequential map on one
 13:   processor and a PETSc MPI map on more than one processor.

 15:   Collective on PetscMap

 17:   Input Parameter:
 18: . map - The map

 20:   Level: intermediate

 22: .keywords: PetscMap, set, options, database, type
 23: .seealso: PetscMapSetFromOptions(), PetscMapSetType()
 24: */
 25: static int PetscMapSetTypeFromOptions_Private(PetscMap map)
 26: {
 27:   PetscTruth opt;
 28:   char      *defaultType;
 29:   char       typeName[256];
 30:   int        numProcs;
 31:   int        ierr;

 34:   if (map->type_name != PETSC_NULL) {
 35:     defaultType = map->type_name;
 36:   } else {
 37:     MPI_Comm_size(map->comm, &numProcs);
 38:     if (numProcs > 1) {
 39:       defaultType = MAP_MPI;
 40:     } else {
 41:       defaultType = MAP_SEQ;
 42:     }
 43:   }

 45:   if (!PetscMapRegisterAllCalled) {
 46:     PetscMapRegisterAll(PETSC_NULL);
 47:   }
 48:   PetscOptionsList("-map_type", "PetscMap type"," PetscMapSetType", PetscMapList, defaultType, typeName, 256, &opt);
 49: 
 50:   if (opt == PETSC_TRUE) {
 51:     PetscMapSetType(map, typeName);
 52:   } else {
 53:     PetscMapSetType(map, defaultType);
 54:   }
 55:   return(0);
 56: }

 58: /*@C
 59:   PetscMapSetFromOptions - Configures the map from the options database.

 61:   Collective on PetscMap

 63:   Input Parameter:
 64: . map - The map

 66:   Notes:  To see all options, run your program with the -help option, or consult the users manual.
 67:           Must be called after PetscMapCreate() but before the map is used.

 69:   Level: intermediate

 71:   Concepts: maptors^setting options
 72:   Concepts: maptors^setting type

 74: .keywords: PetscMap, set, options, database
 75: .seealso: PetscMapCreate(), PetscMapPrintHelp(), PetscMaphSetOptionsPrefix()
 76: @*/
 77: int PetscMapSetFromOptions(PetscMap map)
 78: {
 79:   PetscTruth opt;
 80:   int        ierr;


 85:   PetscOptionsBegin(map->comm, map->prefix, "PetscMap options", "PetscMap");

 87:   /* Handle generic maptor options */
 88:   PetscOptionsHasName(PETSC_NULL, "-help", &opt);
 89:   if (opt == PETSC_TRUE) {
 90:     PetscMapPrintHelp(map);
 91:   }

 93:   /* Handle map type options */
 94:   PetscMapSetTypeFromOptions_Private(map);

 96:   /* Handle specific maptor options */
 97:   if (map->ops->setfromoptions != PETSC_NULL) {
 98:     (*map->ops->setfromoptions)(map);
 99:   }

101:   PetscOptionsEnd();

103:   return(0);
104: }

106: /*@
107:   PetscMapPrintHelp - Prints all options for the PetscMap.

109:   Input Parameter:
110: . map - The map

112:   Options Database Keys:
113: $  -help, -h

115:   Level: intermediate

117: .keywords: PetscMap, help
118: .seealso: PetscMapSetFromOptions()
119: @*/
120: int PetscMapPrintHelp(PetscMap map)
121: {
122:   char p[64];
123:   int  ierr;


128:   PetscStrcpy(p, "-");
129:   if (map->prefix != PETSC_NULL) {
130:     PetscStrcat(p, map->prefix);
131:   }

133:   (*PetscHelpPrintf)(map->comm, "PetscMap options ------------------------------------------------n");
134:   (*PetscHelpPrintf)(map->comm,"   %smap_type <typename> : Sets the map typen", p);
135:   return(0);
136: }

138: /*@C
139:    PetscMapDestroy - Destroys a map object.

141:    Not Collective

143:    Input Parameter:
144: .  m - the map object

146:    Level: developer

148: .seealso: PetscMapCreateMPI()

150: @*/
151: int PetscMapDestroy(PetscMap map)
152: {

157:   if (--map->refct > 0) return(0);
158:   if (map->range != PETSC_NULL) {
159:     PetscFree(map->range);
160:   }
161:   if (map->ops->destroy != PETSC_NULL) {
162:     (*map->ops->destroy)(map);
163:   }
164:   PetscLogObjectDestroy(map);
165:   PetscHeaderDestroy(map);
166:   return(0);
167: }

169: /*@C
170:   PetscMapSetLocalSize - Sets the number of elements associated with this processor.

172:   Not Collective

174:   Input Parameters:
175: + m - the map object
176: - n - the local size

178:   Level: developer

180: .seealso: PetscMapSetSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
181: Concepts: PetscMap^local size
182: @*/
183: int PetscMapSetLocalSize(PetscMap m,int n)
184: {
187:   m->n = n;
188:   return(0);
189: }

191: /*@C
192:    PetscMapGetLocalSize - Gets the number of elements associated with this processor.

194:    Not Collective

196:    Input Parameter:
197: .  m - the map object

199:    Output Parameter:
200: .  n - the local size

202:    Level: developer

204: .seealso: PetscMapGetSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()

206:    Concepts: PetscMap^local size

208: @*/
209: int PetscMapGetLocalSize(PetscMap m,int *n)
210: {
214:   *n = m->n;
215:   return(0);
216: }

218: /*@C
219:   PetscMapSetSize - Sets the total number of elements associated with this map.

221:   Not Collective

223:   Input Parameters:
224: + m - the map object
225: - N - the global size

227:   Level: developer

229: .seealso: PetscMapSetLocalSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
230:  Concepts: PetscMap^size
231: @*/
232: int PetscMapSetSize(PetscMap m,int N)
233: {
236:   m->N = N;
237:   return(0);
238: }

240: /*@C
241:    PetscMapGetSize - Gets the total number of elements associated with this map.

243:    Not Collective

245:    Input Parameter:
246: .  m - the map object

248:    Output Parameter:
249: .  N - the global size

251:    Level: developer

253: .seealso: PetscMapGetLocalSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()

255:    Concepts: PetscMap^size
256: @*/
257: int PetscMapGetSize(PetscMap m,int *N)
258: {
262:   *N = m->N;
263:   return(0);
264: }

266: /*@C
267:    PetscMapGetLocalRange - Gets the local ownership range for this procesor.

269:    Not Collective

271:    Input Parameter:
272: .  m - the map object

274:    Output Parameter:
275: +  rstart - the first local index, pass in PETSC_NULL if not interested 
276: -  rend   - the last local index + 1, pass in PETSC_NULL if not interested

278:    Level: developer

280: .seealso: PetscMapGetLocalSize(), PetscMapGetGlobalRange()
281: @*/
282: int PetscMapGetLocalRange(PetscMap m,int *rstart,int *rend)
283: {
288:   if (rstart) *rstart = m->rstart;
289:   if (rend)   *rend   = m->rend;
290:   return(0);
291: }

293: /*@C
294:    PetscMapGetGlobalRange - Gets the ownership ranges for all processors.

296:    Not Collective

298:    Input Parameter:
299: .  m - the map object

301:    Output Parameter:
302: .  range - array of size + 1 where size is the size of the communicator 
303:            associated with the map. range[rank], range[rank+1] is the 
304:            range for processor 

306:    Level: developer

308: .seealso: PetscMapGetSize(), PetscMapGetLocalRange()

310: @*/
311: int PetscMapGetGlobalRange(PetscMap m,int *range[])
312: {
316:   *range = m->range;
317:   return(0);
318: }