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: #undef __FUNCT__  
 14: /*@C
 15:   PetscMapSetType - Builds a map, for a particular map implementation.

 17:   Collective on PetscMap

 19:   Input Parameters:
 20: + map    - The PetscMap object
 21: - method - The name of the map type

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

 27:   Notes:
 28:   See "petsc/include/vec.h" for available vector types (for instance, MAP_MPI).

 30:   Level: intermediate

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

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

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

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

 58:   PetscObjectChangeTypeName((PetscObject) map, method);
 59:   return(0);
 60: }

 62: #undef __FUNCT__
 64: /*@C
 65:   PetscMapGetType - Gets the map type name (as a string) from the PetscMap.

 67:   Not collective

 69:   Input Parameter:
 70: . map  - The map

 72:   Output Parameter:
 73: . type - The map type name

 75:   Level: intermediate

 77: .keywords: map, get, type, name
 78: .seealso PetscMapSetType(), PetscMapCreate()
 79: @*/
 80: int PetscMapGetType(PetscMap map, PetscMapType *type)
 81: {

 87:   if (PetscMapRegisterAllCalled == PETSC_FALSE) {
 88:     PetscMapRegisterAll(PETSC_NULL);
 89:   }
 90:   *type = map->type_name;
 91:   return(0);
 92: }

 94: #undef __FUNCT__  
 96: /*@C
 97:   PetscMapSetSerializeType - Sets the serialization method for the map.

 99:   Collective on PetscMap

101:   Input Parameters:
102: + map    - The PetscMap object
103: - method - The map serialization type name

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

109:    Notes:
110:    See "petsc/include/petscvec.h" for available methods (for instance)
111: +  MAP_SER_SEQ_BINARY - Sequential map to binary file
112: -  MAP_SER_MPI_BINARY - MPI map to binary file

114:    Level: intermediate

116: .keywords: PetscMap, set, type, serialization
117: @*/
118: int PetscMapSetSerializeType(PetscMap map, PetscMapSerializeType method)
119: {
120:   int      (*r)(MPI_Comm, PetscMap *, PetscViewer, PetscTruth);
121:   PetscTruth match;
122:   int        ierr;

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

129:   /* Get the function pointers for the method requested but do not call */
130:   if (PetscMapSerializeRegisterAllCalled == PETSC_FALSE) {
131:     PetscMapSerializeRegisterAll(PETSC_NULL);
132:   }
133:   PetscFListFind(map->comm, PetscMapSerializeList, method, (void (**)(void)) &r);
134:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown map serialization type: %s", method);

136:   PetscObjectChangeSerializeName((PetscObject) map, method);
137:   return(0);
138: }

140: #undef __FUNCT__
142: /*@C
143:   PetscMapGetSerializeType - Gets the map serialization type name (as a string) from the PetscMap.

145:   Not collective

147:   Input Parameter:
148: . map  - The map

150:   Output Parameter:
151: . type - The map type name

153:   Level: intermediate

155: .keywords: map, get, type, name
156: .seealso PetscMapSetSerializeType(), PetscMapCreate()
157: @*/
158: int PetscMapGetSerializeType(PetscMap map, PetscMapSerializeType *type)
159: {

165:   if (PetscMapSerializeRegisterAllCalled == PETSC_FALSE) {
166:     PetscMapSerializeRegisterAll(PETSC_NULL);
167:   }
168:   *type = map->serialize_name;
169:   return(0);
170: }

172: /*--------------------------------------------------------------------------------------------------------------------*/
173: /*MC
174:   PetscMapRegisterDynamic - Adds a new map component implementation

176:   Synopsis:
177:   PetscMapRegisterDynamic(char *name, char *path, char *func_name, int (*create_func)(PetscMap))

179:   Not Collective

181:   Input Parameters:
182: + name        - The name of a new user-defined creation routine
183: . path        - The path (either absolute or relative) of the library containing this routine
184: . func_name   - The name of routine to create method context
185: - create_func - The creation routine itself

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

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

192:   Sample usage:
193: .vb
194:     PetscMapRegisterDynamic("my_map","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscMapCreate", MyPetscMapCreate);
195: .ve

197:   Then, your map type can be chosen with the procedural interface via
198: .vb
199:     PetscMapCreate(MPI_Comm, PetscMap *);
200:     PetscMapSetType(PetscMap,"my_map_name");
201: .ve
202:    or at runtime via the option
203: .vb
204:     -map_type my_map_name
205: .ve

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

209:   Level: advanced

211: .keywords: PetscMap, register
212: .seealso: PetscMapRegisterAll(), PetscMapRegisterDestroy()
213: M*/

215: #undef __FUNCT__  
217: int PetscMapRegister(const char sname[], const char path[], const char name[], int (*function)(PetscMap))
218: {
219:   char fullname[PETSC_MAX_PATH_LEN];
220:   int  ierr;

223:   PetscStrcpy(fullname, path);
224:   PetscStrcat(fullname, ":");
225:   PetscStrcat(fullname, name);
226:   PetscFListAdd(&PetscMapList, sname, fullname, (void (*)(void)) function);
227:   return(0);
228: }

230: /*CM
231:   PetscMapSerializeRegisterDynamic - Adds a serialization method to the map package.

233:   Synopsis:

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

238:   Not Collective

240:   Input Parameters:
241: + name           - The name of a new user-defined serialization routine
242: . path           - The path (either absolute or relative) of the library containing this routine
243: . func_name      - The name of the serialization routine
244: - serialize_func - The serialization routine itself

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

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

251:   Sample usage:
252: .vb
253:   PetscMapSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
254: .ve

256:   Then, your serialization can be chosen with the procedural interface via
257: .vb
258:     PetscMapSetSerializeType(map, "my_store")
259: .ve
260:   or at runtime via the option
261: .vb
262:     -map_serialize_type my_store
263: .ve

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

267:   Level: advanced

269: .keywords: PetscMap, register
270: .seealso: PetscMapSerializeRegisterAll(), PetscMapSerializeRegisterDestroy()
271: M*/
272: #undef __FUNCT__  
274: int PetscMapSerializeRegister(const char sname[], const char path[], const char name[],
275:                           int (*function)(MPI_Comm, PetscMap *, PetscViewer, PetscTruth))
276: {
277:   char fullname[PETSC_MAX_PATH_LEN];
278:   int  ierr;

281:   PetscStrcpy(fullname, path);
282:   PetscStrcat(fullname, ":");
283:   PetscStrcat(fullname, name);
284:   PetscFListAdd(&PetscMapSerializeList, sname, fullname, (void (*)(void)) function);
285:   return(0);
286: }

288: /*--------------------------------------------------------------------------------------------------------------------*/
289: #undef __FUNCT__  
291: /*@C
292:   PetscMapRegisterDestroy - Frees the list of PetscMap methods that were registered by PetscMapRegister().

294:   Not collective

296:   Level: advanced

298: .keywords: map, register, destroy
299: .seealso: PetscMapRegister(), PetscMapRegisterAll(), PetscMapSerializeRegisterDestroy()
300: @*/
301: int PetscMapRegisterDestroy()
302: {

306:   if (PetscMapList != PETSC_NULL) {
307:     PetscFListDestroy(&PetscMapList);
308:     PetscMapList = PETSC_NULL;
309:   }
310:   PetscMapRegisterAllCalled = PETSC_FALSE;
311:   return(0);
312: }

314: #undef __FUNCT__  
316: /*@C
317:   PetscMapSerializeRegisterDestroy - Frees the list of serialization routines for
318:   maptors that were registered by PetscMapSerializeRegister().

320:   Not collective

322:   Level: advanced

324: .keywords: PetscMap, map, register, destroy
325: .seealso: PetscMapSerializeRegisterAll()
326: @*/
327: int PetscMapSerializeRegisterDestroy()
328: {

332:   if (PetscMapSerializeList != PETSC_NULL) {
333:     PetscFListDestroy(&PetscMapSerializeList);
334:     PetscMapSerializeList = PETSC_NULL;
335:   }
336:   PetscMapSerializeRegisterAllCalled = PETSC_FALSE;
337:   return(0);
338: }