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: #undef __FUNCT__  
 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 int PetscMapSetTypeFromOptions_Private(PetscMap map)
 28: {
 29:   PetscTruth opt;
 30:   char      *defaultType;
 31:   char       typeName[256];
 32:   int        numProcs;
 33:   int        ierr;

 36:   if (map->type_name != PETSC_NULL) {
 37:     defaultType = map->type_name;
 38:   } else {
 39:     MPI_Comm_size(map->comm, &numProcs);
 40:     if (numProcs > 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 == PETSC_TRUE) {
 53:     PetscMapSetType(map, typeName);
 54:   } else {
 55:     PetscMapSetType(map, defaultType);
 56:   }
 57:   return(0);
 58: }

 60: #undef __FUNCT__  
 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: int PetscMapSetFromOptions(PetscMap map)
 82: {
 83:   PetscTruth opt;
 84:   int        ierr;


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

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

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

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

105:   PetscOptionsEnd();

107:   return(0);
108: }

110: #undef __FUNCT__  
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: int PetscMapPrintHelp(PetscMap map)
127: {
128:   char p[64];
129:   int  ierr;


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

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

144: #undef __FUNCT__  
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: int PetscMapDestroy(PetscMap map)
160: {

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

177: #undef __FUNCT__  
179: /*@C
180:   PetscMapSetLocalSize - Sets the number of elements associated with this processor.

182:   Not Collective

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

188:   Level: developer

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

201: #undef __FUNCT__  
203: /*@C
204:    PetscMapGetLocalSize - Gets the number of elements associated with this processor.

206:    Not Collective

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

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

214:    Level: developer

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

218:    Concepts: PetscMap^local size

220: @*/
221: int PetscMapGetLocalSize(PetscMap m,int *n)
222: {
226:   *n = m->n;
227:   return(0);
228: }

230: #undef __FUNCT__  
232: /*@C
233:   PetscMapSetSize - Sets the total number of elements associated with this map.

235:   Not Collective

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

241:   Level: developer

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

254: #undef __FUNCT__  
256: /*@C
257:    PetscMapGetSize - Gets the total number of elements associated with this map.

259:    Not Collective

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

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

267:    Level: developer

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

271:    Concepts: PetscMap^size
272: @*/
273: int PetscMapGetSize(PetscMap m,int *N)
274: {
278:   *N = m->N;
279:   return(0);
280: }

282: #undef __FUNCT__  
284: /*@C
285:    PetscMapGetLocalRange - Gets the local ownership range for this procesor.

287:    Not Collective

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

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

296:    Level: developer

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

311: #undef __FUNCT__  
313: /*@C
314:    PetscMapGetGlobalRange - Gets the ownership ranges for all processors.

316:    Not Collective

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

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

326:    Level: developer

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

330: @*/
331: int PetscMapGetGlobalRange(PetscMap m,int *range[])
332: {
336:   *range = m->range;
337:   return(0);
338: }