Actual source code: mapreg.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: mapreg.c,v 1.2 2000/01/10 03:18:14 knepley Exp $";
  3: #endif

 5:  #include src/vec/vecimpl.h

  7: PetscFList PetscMapList                       = PETSC_NULL;
  8: PetscTruth PetscMapRegisterAllCalled          = PETSC_FALSE;
  9: PetscFList PetscMapSerializeList              = PETSC_NULL;
 10: PetscTruth PetscMapSerializeRegisterAllCalled = PETSC_FALSE;

 12: /*@C
 13:   PetscMapSetType - Builds a map, for a particular map implementation.

 15:   Collective on PetscMap

 17:   Input Parameters:
 18: + map    - The PetscMap object
 19: - method - The name of the map type

 21:   Options Database Command:
 22: . -map_type <method> - Sets the method; use -help for a list
 23:                        of available methods (for instance, mpi)

 25:   Notes:
 26:   See "petsc/include/vec.h" for available vector types (for instance, MAPMPI).

 28:   Level: intermediate

 30: .keywords: map, set, type
 31: .seealso PetscMapGetType(), PetscMapCreate()
 32: @*/
 33: int PetscMapSetType(PetscMap map, PetscMapType method)
 34: {
 35:   int      (*r)(PetscMap);
 36:   PetscTruth match;
 37:   int        ierr;

 41:   PetscTypeCompare((PetscObject) map, method, &match);
 42:   if (match == PETSC_TRUE) return(0);

 44:   /* Get the function pointers for the method requested */
 45:   if (PetscMapRegisterAllCalled == PETSC_FALSE) {
 46:     PetscMapRegisterAll(PETSC_NULL);
 47:   }
 48:   PetscFListFind(map->comm, PetscMapList, method, (void (**)(void)) &r);
 49:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown map type: %s", method);

 51:   if (map->ops->destroy != PETSC_NULL) {
 52:     (*map->ops->destroy)(map);
 53:   }
 54:   (*r)(map);

 56:   PetscObjectChangeTypeName((PetscObject) map, method);
 57:   return(0);
 58: }

 60: /*@C
 61:   PetscMapGetType - Gets the map type name (as a string) from the PetscMap.

 63:   Not collective

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

 68:   Output Parameter:
 69: . type - The map type name

 71:   Level: intermediate

 73: .keywords: map, get, type, name
 74: .seealso PetscMapSetType(), PetscMapCreate()
 75: @*/
 76: int PetscMapGetType(PetscMap map, PetscMapType *type)
 77: {

 83:   if (PetscMapRegisterAllCalled == PETSC_FALSE) {
 84:     PetscMapRegisterAll(PETSC_NULL);
 85:   }
 86:   *type = map->type_name;
 87:   return(0);
 88: }

 90: /*@C
 91:   PetscMapSetSerializeType - Sets the serialization method for the map.

 93:   Collective on PetscMap

 95:   Input Parameters:
 96: + map    - The PetscMap object
 97: - method - The map serialization type name

 99:   Options Database Command:
100: . -map_serialize_type <method> - Sets the method; use -help for a list
101:                                  of available methods (for instance, seq_binary)

103:    Notes:
104:    See "petsc/include/petscvec.h" for available methods (for instance)
105: +  MAP_SER_SEQ_BINARY - Sequential map to binary file
106: -  MAP_SER_MPI_BINARY - MPI map to binary file

108:    Level: intermediate

110: .keywords: PetscMap, set, type, serialization
111: @*/
112: int PetscMapSetSerializeType(PetscMap map, PetscMapSerializeType method)
113: {
114:   int      (*r)(MPI_Comm, PetscMap *, PetscViewer, PetscTruth);
115:   PetscTruth match;
116:   int        ierr;

120:   PetscSerializeCompare((PetscObject) map, method, &match);
121:   if (match == PETSC_TRUE) return(0);

123:   /* Get the function pointers for the method requested but do not call */
124:   if (PetscMapSerializeRegisterAllCalled == PETSC_FALSE) {
125:     PetscMapSerializeRegisterAll(PETSC_NULL);
126:   }
127:   PetscFListFind(map->comm, PetscMapSerializeList, method, (void (**)(void)) &r);
128:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown map serialization type: %s", method);

130:   PetscObjectChangeSerializeName((PetscObject) map, method);
131:   return(0);
132: }

134: /*@C
135:   PetscMapGetSerializeType - Gets the map serialization type name (as a string) from the PetscMap.

137:   Not collective

139:   Input Parameter:
140: . map  - The map

142:   Output Parameter:
143: . type - The map type name

145:   Level: intermediate

147: .keywords: map, get, type, name
148: .seealso PetscMapSetSerializeType(), PetscMapCreate()
149: @*/
150: int PetscMapGetSerializeType(PetscMap map, PetscMapSerializeType *type)
151: {

157:   if (PetscMapSerializeRegisterAllCalled == PETSC_FALSE) {
158:     PetscMapSerializeRegisterAll(PETSC_NULL);
159:   }
160:   *type = map->serialize_name;
161:   return(0);
162: }

164: /*--------------------------------------------------------------------------------------------------------------------*/
165: /*@CM
166:   PetscMapRegisterDynamic - Adds a new map component implementation

168:   Synopsis:
169:   PetscMapRegisterDynamic(char *name, char *path, char *func_name, int (*create_func)(PetscMap))

171:   Not Collective

173:   Input Parameters:
174: + name        - The name of a new user-defined creation routine
175: . path        - The path (either absolute or relative) of the library containing this routine
176: . func_name   - The name of routine to create method context
177: - create_func - The creation routine itself

179:   Notes:
180:   PetscMapRegister() may be called multiple times to add several user-defined maptors

182:   If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.

184:   Sample usage:
185: .vb
186:     PetscMapRegisterDynamic("my_map","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscMapCreate", MyPetscMapCreate);
187: .ve

189:   Then, your map type can be chosen with the procedural interface via
190: .vb
191:     PetscMapCreate(MPI_Comm, PetscMap *);
192:     PetscMapSetType(PetscMap,"my_map_name");
193: .ve
194:    or at runtime via the option
195: .vb
196:     -map_type my_map_name
197: .ve

199:   Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.

201:   Level: advanced

203: .keywords: PetscMap, register
204: .seealso: PetscMapRegisterAll(), PetscMapRegisterDestroy()
205: M*/

207: int PetscMapRegister(const char sname[], const char path[], const char name[], int (*function)(PetscMap))
208: {
209:   char fullname[256];
210:   int  ierr;

213:   PetscStrcpy(fullname, path);
214:   PetscStrcat(fullname, ":");
215:   PetscStrcat(fullname, name);
216:   PetscFListAdd(&PetscMapList, sname, fullname, (void (*)(void)) function);
217:   return(0);
218: }

220: /*@M
221:   PetscMapSerializeRegisterDynamic - Adds a serialization method to the map package.

223:   Synopsis:

225:   PetscMapSerializeRegisterDynamic(char *name, char *path, char *func_name,
226:                               int (*serialize_func)(MPI_Comm, PetscMap *, PetscViewer, PetscTruth))

228:   Not Collective

230:   Input Parameters:
231: + name           - The name of a new user-defined serialization routine
232: . path           - The path (either absolute or relative) of the library containing this routine
233: . func_name      - The name of the serialization routine
234: - serialize_func - The serialization routine itself

236:   Notes:
237:   PetscMapSerializeRegister() may be called multiple times to add several user-defined serializers.

239:   If dynamic libraries are used, then the fourth input argument (serialize_func) is ignored.

241:   Sample usage:
242: .vb
243:   PetscMapSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
244: .ve

246:   Then, your serialization can be chosen with the procedural interface via
247: .vb
248:     PetscMapSetSerializeType(map, "my_store")
249: .ve
250:   or at runtime via the option
251: .vb
252:     -map_serialize_type my_store
253: .ve

255:   Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.

257:   Level: advanced

259: .keywords: PetscMap, register
260: .seealso: PetscMapSerializeRegisterAll(), PetscMapSerializeRegisterDestroy()
261: M*/
262: int PetscMapSerializeRegister(const char sname[], const char path[], const char name[],
263:                           int (*function)(MPI_Comm, PetscMap *, PetscViewer, PetscTruth))
264: {
265:   char fullname[256];
266:   int  ierr;

269:   PetscStrcpy(fullname, path);
270:   PetscStrcat(fullname, ":");
271:   PetscStrcat(fullname, name);
272:   PetscFListAdd(&PetscMapSerializeList, sname, fullname, (void (*)(void)) function);
273:   return(0);
274: }

276: /*--------------------------------------------------------------------------------------------------------------------*/
277: /*@C
278:   PetscMapRegisterDestroy - Frees the list of PetscMap methods that were registered by PetscMapRegister().

280:   Not collective

282:   Level: advanced

284: .keywords: map, register, destroy
285: .seealso: PetscMapRegister(), PetscMapRegisterAll(), PetscMapSerializeRegisterDestroy()
286: @*/
287: int PetscMapRegisterDestroy()
288: {

292:   if (PetscMapList != PETSC_NULL) {
293:     PetscFListDestroy(&PetscMapList);
294:     PetscMapList = PETSC_NULL;
295:   }
296:   PetscMapRegisterAllCalled = PETSC_FALSE;
297:   return(0);
298: }

300: /*@C
301:   PetscMapSerializeRegisterDestroy - Frees the list of serialization routines for
302:   maptors that were registered by PetscMapSerializeRegister().

304:   Not collective

306:   Level: advanced

308: .keywords: PetscMap, map, register, destroy
309: .seealso: PetscMapSerializeRegisterAll()
310: @*/
311: int PetscMapSerializeRegisterDestroy()
312: {

316:   if (PetscMapSerializeList != PETSC_NULL) {
317:     PetscFListDestroy(&PetscMapSerializeList);
318:     PetscMapSerializeList = PETSC_NULL;
319:   }
320:   PetscMapSerializeRegisterAllCalled = PETSC_FALSE;
321:   return(0);
322: }