Actual source code: map.c

  1: /*
  2:      Provides the interface functions for all map operations.
  3:    These are the map functions the user calls.
  4: */
 5:  #include vecimpl.h

  7: /* Logging support */
  8: PetscCookie MAP_COOKIE = 0;

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

 16:   Collective on PetscMap

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

 21:   Level: intermediate

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

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

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

 61: /*@C
 62:   PetscMapSetFromOptions - Configures the map from the options database.

 64:   Collective on PetscMap

 66:   Input Parameter:
 67: . map - The map

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

 72:   Level: intermediate

 74:   Concepts: maptors^setting options
 75:   Concepts: maptors^setting type

 77: .keywords: PetscMap, set, options, database
 78: .seealso: PetscMapCreate(), PetscMapPrintHelp(), PetscMaphSetOptionsPrefix()
 79: @*/
 80: PetscErrorCode PetscMapSetFromOptions(PetscMap map)
 81: {
 82:   PetscTruth opt;


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

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

 96:   /* Handle map type options */
 97:   PetscMapSetTypeFromOptions_Private(map);

 99:   /* Handle specific maptor options */
100:   if (map->ops->setfromoptions != PETSC_NULL) {
101:     (*map->ops->setfromoptions)(map);
102:   }

104:   PetscOptionsEnd();

106:   return(0);
107: }

111: /*@
112:   PetscMapPrintHelp - Prints all options for the PetscMap.

114:   Input Parameter:
115: . map - The map

117:   Options Database Keys:
118: $  -help, -h

120:   Level: intermediate

122: .keywords: PetscMap, help
123: .seealso: PetscMapSetFromOptions()
124: @*/
125: PetscErrorCode PetscMapPrintHelp(PetscMap map)
126: {
127:   char p[64];


133:   PetscStrcpy(p, "-");
134:   if (map->prefix != PETSC_NULL) {
135:     PetscStrcat(p, map->prefix);
136:   }

138:   (*PetscHelpPrintf)(map->comm, "PetscMap options ------------------------------------------------\n");
139:   (*PetscHelpPrintf)(map->comm,"   %smap_type <typename> : Sets the map type\n", p);
140:   return(0);
141: }

145: /*@C
146:    PetscMapDestroy - Destroys a map object.

148:    Not Collective

150:    Input Parameter:
151: .  m - the map object

153:    Level: developer

155: .seealso: PetscMapCreateMPI()

157: @*/
158: PetscErrorCode PetscMapDestroy(PetscMap map)
159: {

164:   if (--map->refct > 0) return(0);
165:   if (map->range != PETSC_NULL) {
166:     PetscFree(map->range);
167:   }
168:   if (map->ops->destroy != PETSC_NULL) {
169:     (*map->ops->destroy)(map);
170:   }
171:   PetscLogObjectDestroy(map);
172:   PetscHeaderDestroy(map);
173:   return(0);
174: }

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

181:   Not Collective

183:   Input Parameters:
184: + m - the map object
185: - n - the local size

187:   Level: developer

189: .seealso: PetscMapSetSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
190: Concepts: PetscMap^local size
191: @*/
192: PetscErrorCode PetscMapSetLocalSize(PetscMap m,PetscInt n)
193: {
196:   m->n = n;
197:   return(0);
198: }

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

205:    Not Collective

207:    Input Parameter:
208: .  m - the map object

210:    Output Parameter:
211: .  n - the local size

213:    Level: developer

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

217:    Concepts: PetscMap^local size

219: @*/
220: PetscErrorCode PetscMapGetLocalSize(PetscMap m,PetscInt *n)
221: {
225:   *n = m->n;
226:   return(0);
227: }

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

234:   Not Collective

236:   Input Parameters:
237: + m - the map object
238: - N - the global size

240:   Level: developer

242: .seealso: PetscMapSetLocalSize(), PetscMapGetLocalRange(), PetscMapGetGlobalRange()
243:  Concepts: PetscMap^size
244: @*/
245: PetscErrorCode PetscMapSetSize(PetscMap m,PetscInt N)
246: {
249:   m->N = N;
250:   return(0);
251: }

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

258:    Not Collective

260:    Input Parameter:
261: .  m - the map object

263:    Output Parameter:
264: .  N - the global size

266:    Level: developer

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

270:    Concepts: PetscMap^size
271: @*/
272: PetscErrorCode PetscMapGetSize(PetscMap m,PetscInt *N)
273: {
277:   *N = m->N;
278:   return(0);
279: }

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

286:    Not Collective

288:    Input Parameter:
289: .  m - the map object

291:    Output Parameter:
292: +  rstart - the first local index, pass in PETSC_NULL if not interested 
293: -  rend   - the last local index + 1, pass in PETSC_NULL if not interested

295:    Level: developer

297: .seealso: PetscMapGetLocalSize(), PetscMapGetGlobalRange()
298: @*/
299: PetscErrorCode PetscMapGetLocalRange(PetscMap m,PetscInt *rstart,PetscInt *rend)
300: {
305:   if (rstart) *rstart = m->rstart;
306:   if (rend)   *rend   = m->rend;
307:   return(0);
308: }

312: /*@C
313:    PetscMapGetGlobalRange - Gets the ownership ranges for all processors.

315:    Not Collective

317:    Input Parameter:
318: .  m - the map object

320:    Output Parameter:
321: .  range - array of size + 1 where size is the size of the communicator 
322:            associated with the map. range[rank], range[rank+1] is the 
323:            range for processor 

325:    Level: developer

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

329: @*/
330: PetscErrorCode PetscMapGetGlobalRange(PetscMap m,PetscInt *range[])
331: {
335:   *range = m->range;
336:   return(0);
337: }