Actual source code: vecreg.c

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

 5:  #include src/vec/vecimpl.h

  7: PetscFList VecList                       = PETSC_NULL;
  8: PetscTruth VecRegisterAllCalled          = PETSC_FALSE;
  9: PetscFList VecSerializeList              = PETSC_NULL;
 10: PetscTruth VecSerializeRegisterAllCalled = PETSC_FALSE;

 12: /*@C
 13:   VecSetType - Builds a vector, for a particular vector implementation.

 15:   Collective on Vec

 17:   Input Parameters:
 18: + vec    - The vector object
 19: - method - The name of the vector type

 21:   Options Database Key:
 22: . -vec_type <type> - Sets the vector type; use -help for a list 
 23:                      of available types

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

 28:   Use VecDuplicate() or VecDuplicateVecs() to form additional vectors of the same type as an existing vector.

 30:   Level: intermediate

 32: .keywords: vector, set, type
 33: .seealso: VecGetType(), VecCreate()
 34: @*/
 35: int VecSetType(Vec vec, VecType method)
 36: {
 37:   int      (*r)(Vec);
 38:   PetscTruth match;
 39:   int        ierr;

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

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

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

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

 62: /*@C
 63:   VecGetType - Gets the vector type name (as a string) from the Vec.

 65:   Not Collective

 67:   Input Parameter:
 68: . vec  - The vector

 70:   Output Parameter:
 71: . type - The vector type name

 73:   Level: intermediate

 75: .keywords: vector, get, type, name
 76: .seealso: VecSetType(), VecCreate()
 77: @*/
 78: int VecGetType(Vec vec, VecType *type)
 79: {

 85:   if (VecRegisterAllCalled == PETSC_FALSE) {
 86:     VecRegisterAll(PETSC_NULL);
 87:   }
 88:   *type = vec->type_name;
 89:   return(0);
 90: }

 92: /*@C
 93:   VecSetSerializeType - Sets the serialization method for the vector.

 95:   Collective on Vec

 97:   Input Parameters:
 98: + vec    - The Vec object
 99: - method - The vector serialization type name

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

105:    Notes:
106:    See "petsc/include/petscvec.h" for available methods (for instance)
107: +  VEC_SER_SEQ_BINARY - Sequential vector to binary file
108: -  VEC_SER_MPI_BINARY - MPI vector to binary file

110:    Level: intermediate

112: .keywords: Vec, set, type, serialization
113: @*/
114: int VecSetSerializeType(Vec vec, VecSerializeType method)
115: {
116:   int      (*r)(MPI_Comm, Vec *, PetscViewer, PetscTruth);
117:   PetscTruth match;
118:   int        ierr;

122:   PetscSerializeCompare((PetscObject) vec, method, &match);
123:   if (match == PETSC_TRUE) return(0);

125:   /* Get the function pointers for the method requested but do not call */
126:   if (VecSerializeRegisterAllCalled == PETSC_FALSE) {
127:     VecSerializeRegisterAll(PETSC_NULL);
128:   }
129:   PetscFListFind(vec->comm, VecSerializeList, method, (void (**)(void)) &r);
130:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown vector serialization type: %s", method);

132:   PetscObjectChangeSerializeName((PetscObject) vec, method);
133:   return(0);
134: }

136: /*@C
137:   VecGetSerializeType - Gets the map serialization type name (as a string) from the Vec.

139:   Not collective

141:   Input Parameter:
142: . map  - The map

144:   Output Parameter:
145: . type - The map type name

147:   Level: intermediate

149: .keywords: map, get, type, name
150: .seealso VecSetSerializeType(), VecCreate()
151: @*/
152: int VecGetSerializeType(Vec map, VecSerializeType *type)
153: {

159:   if (VecSerializeRegisterAllCalled == PETSC_FALSE) {
160:     VecSerializeRegisterAll(PETSC_NULL);
161:   }
162:   *type = map->serialize_name;
163:   return(0);
164: }

166: /*--------------------------------------------------------------------------------------------------------------------*/
167: /*MC
168:   VecRegisterDynamic - Adds a new vector component implementation

170:   Synopsis:
171:   VecRegisterDynamic(char *name, char *path, char *func_name, int (*create_func)(Vec))

173:   Not Collective

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

181:   Notes:
182:   VecRegister() may be called multiple times to add several user-defined vectors

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

186:   Sample usage:
187: .vb
188:     VecRegisterDynamic("my_vec","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyVectorCreate", MyVectorCreate);
189: .ve

191:   Then, your vector type can be chosen with the procedural interface via
192: .vb
193:     VecCreate(MPI_Comm, Vec *);
194:     VecSetType(Vec,"my_vector_name");
195: .ve
196:    or at runtime via the option
197: .vb
198:     -vec_type my_vector_name
199: .ve

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

203:   Level: advanced

205: .keywords: Vec, register
206: .seealso: VecRegisterAll(), VecRegisterDestroy()
207: M*/

209: int VecRegister(const char sname[], const char path[], const char name[], int (*function)(Vec))
210: {
211:   char fullname[256];
212:   int  ierr;

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

222: /*MC
223:   VecSerializeRegisterDynamic - Adds a serialization method to the vec package.

225:   Synopsis:

227:   VecSerializeRegisterDynamic(char *name, char *path, char *func_name,
228:                               int (*serialize_func)(MPI_Comm, Vec *, PetscViewer, PetscTruth))

230:   Not Collective

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

238:   Notes:
239:   VecSerializeRegister() may be called multiple times to add several user-defined serializers.

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

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

248:   Then, your serialization can be chosen with the procedural interface via
249: .vb
250:     VecSetSerializeType(vec, "my_store")
251: .ve
252:   or at runtime via the option
253: .vb
254:     -vec_serialize_type my_store
255: .ve

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

259:   Level: advanced

261: .keywords: Vec, register
262: .seealso: VecSerializeRegisterAll(), VecSerializeRegisterDestroy()
263: M*/
264: int VecSerializeRegister(const char sname[], const char path[], const char name[],
265:                           int (*function)(MPI_Comm, Vec *, PetscViewer, PetscTruth))
266: {
267:   char fullname[256];
268:   int  ierr;

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

278: /*--------------------------------------------------------------------------------------------------------------------*/
279: /*@C
280:    VecRegisterDestroy - Frees the list of Vec methods that were registered by VecRegister().

282:    Not Collective

284:    Level: advanced

286: .keywords: Vec, register, destroy
287: .seealso: VecRegister(), VecRegisterAll(), VecSerializeRegisterDestroy()
288: @*/
289: int VecRegisterDestroy(void)
290: {

294:   if (VecList != PETSC_NULL) {
295:     PetscFListDestroy(&VecList);
296:     VecList = PETSC_NULL;
297:   }
298:   VecRegisterAllCalled = PETSC_FALSE;
299:   return(0);
300: }

302: /*@C
303:   VecSerializeRegisterDestroy - Frees the list of serialization routines for
304:   vectors that were registered by VecSerializeRegister().

306:   Not collective

308:   Level: advanced

310: .keywords: Vec, vector, register, destroy
311: .seealso: VecSerializeRegisterAll()
312: @*/
313: int VecSerializeRegisterDestroy()
314: {

318:   if (VecSerializeList != PETSC_NULL) {
319:     PetscFListDestroy(&VecSerializeList);
320:     VecSerializeList = PETSC_NULL;
321:   }
322:   VecSerializeRegisterAllCalled = PETSC_FALSE;
323:   return(0);
324: }