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

 17:   Collective on Vec

 19:   Input Parameters:
 20: + vec    - The vector object
 21: - method - The name of the vector type

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

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

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

 32:   Level: intermediate

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

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

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

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

 60:   PetscObjectChangeTypeName((PetscObject) vec, method);
 61:   return(0);
 62: }

 64: #undef __FUNCT__  
 66: /*@C
 67:   VecGetType - Gets the vector type name (as a string) from the Vec.

 69:   Not Collective

 71:   Input Parameter:
 72: . vec  - The vector

 74:   Output Parameter:
 75: . type - The vector type name

 77:   Level: intermediate

 79: .keywords: vector, get, type, name
 80: .seealso: VecSetType(), VecCreate()
 81: @*/
 82: int VecGetType(Vec vec, VecType *type)
 83: {

 89:   if (VecRegisterAllCalled == PETSC_FALSE) {
 90:     VecRegisterAll(PETSC_NULL);
 91:   }
 92:   *type = vec->type_name;
 93:   return(0);
 94: }

 96: #undef __FUNCT__  
 98: /*@C
 99:   VecSetSerializeType - Sets the serialization method for the vector.

101:   Collective on Vec

103:   Input Parameters:
104: + vec    - The Vec object
105: - method - The vector serialization type name

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

111:    Notes:
112:    See "petsc/include/petscvec.h" for available methods (for instance)
113: +  VEC_SER_SEQ_BINARY - Sequential vector to binary file
114: -  VEC_SER_MPI_BINARY - MPI vector to binary file

116:    Level: intermediate

118: .keywords: Vec, set, type, serialization
119: @*/
120: int VecSetSerializeType(Vec vec, VecSerializeType method)
121: {
122:   int      (*r)(MPI_Comm, Vec *, PetscViewer, PetscTruth);
123:   PetscTruth match;
124:   int        ierr;

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

131:   /* Get the function pointers for the method requested but do not call */
132:   if (VecSerializeRegisterAllCalled == PETSC_FALSE) {
133:     VecSerializeRegisterAll(PETSC_NULL);
134:   }
135:   PetscFListFind(vec->comm, VecSerializeList, method, (void (**)(void)) &r);
136:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown vector serialization type: %s", method);

138:   PetscObjectChangeSerializeName((PetscObject) vec, method);
139:   return(0);
140: }

142: #undef __FUNCT__
144: /*@C
145:   VecGetSerializeType - Gets the map serialization type name (as a string) from the Vec.

147:   Not collective

149:   Input Parameter:
150: . map  - The map

152:   Output Parameter:
153: . type - The map type name

155:   Level: intermediate

157: .keywords: map, get, type, name
158: .seealso VecSetSerializeType(), VecCreate()
159: @*/
160: int VecGetSerializeType(Vec map, VecSerializeType *type)
161: {

167:   if (VecSerializeRegisterAllCalled == PETSC_FALSE) {
168:     VecSerializeRegisterAll(PETSC_NULL);
169:   }
170:   *type = map->serialize_name;
171:   return(0);
172: }

174: /*--------------------------------------------------------------------------------------------------------------------*/
175: /*MC
176:   VecRegisterDynamic - Adds a new vector component implementation

178:   Synopsis:
179:   VecRegisterDynamic(char *name, char *path, char *func_name, int (*create_func)(Vec))

181:   Not Collective

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

189:   Notes:
190:   VecRegisterDynamic() may be called multiple times to add several user-defined vectors

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

194:   Sample usage:
195: .vb
196:     VecRegisterDynamic("my_vec","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyVectorCreate", MyVectorCreate);
197: .ve

199:   Then, your vector type can be chosen with the procedural interface via
200: .vb
201:     VecCreate(MPI_Comm, Vec *);
202:     VecSetType(Vec,"my_vector_name");
203: .ve
204:    or at runtime via the option
205: .vb
206:     -vec_type my_vector_name
207: .ve

209:   Notes: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
210:          If your function is not being put into a shared library then use VecRegister() instead
211:         
212:   Level: advanced

214: .keywords: Vec, register
215: .seealso: VecRegisterAll(), VecRegisterDestroy(), VecRegister()
216: M*/

218: #undef __FUNCT__  
220: /*@C
221:   VecRegister - See VecRegisterDynamic()

223:   Level: advanced
224: @*/
225: int VecRegister(const char sname[], const char path[], const char name[], int (*function)(Vec))
226: {
227:   char fullname[PETSC_MAX_PATH_LEN];
228:   int  ierr;

231:   PetscStrcpy(fullname, path);
232:   PetscStrcat(fullname, ":");
233:   PetscStrcat(fullname, name);
234:   PetscFListAdd(&VecList, sname, fullname, (void (*)(void)) function);
235:   return(0);
236: }

238: /*MC
239:   VecSerializeRegisterDynamic - Adds a serialization method to the vec package.

241:   Synopsis:

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

246:   Not Collective

248:   Input Parameters:
249: + name           - The name of a new user-defined serialization routine
250: . path           - The path (either absolute or relative) of the library containing this routine
251: . func_name      - The name of the serialization routine
252: - serialize_func - The serialization routine itself

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

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

259:   Sample usage:
260: .vb
261:   VecSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
262: .ve

264:   Then, your serialization can be chosen with the procedural interface via
265: .vb
266:     VecSetSerializeType(vec, "my_store")
267: .ve
268:   or at runtime via the option
269: .vb
270:     -vec_serialize_type my_store
271: .ve

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

275:   Level: advanced

277: .keywords: Vec, register
278: .seealso: VecSerializeRegisterAll(), VecSerializeRegisterDestroy()
279: M*/
280: #undef __FUNCT__  
282: int VecSerializeRegister(const char sname[], const char path[], const char name[],
283:                           int (*function)(MPI_Comm, Vec *, PetscViewer, PetscTruth))
284: {
285:   char fullname[PETSC_MAX_PATH_LEN];
286:   int  ierr;

289:   PetscStrcpy(fullname, path);
290:   PetscStrcat(fullname, ":");
291:   PetscStrcat(fullname, name);
292:   PetscFListAdd(&VecSerializeList, sname, fullname, (void (*)(void)) function);
293:   return(0);
294: }

296: /*--------------------------------------------------------------------------------------------------------------------*/
297: #undef __FUNCT__  
299: /*@C
300:    VecRegisterDestroy - Frees the list of Vec methods that were registered by VecRegister()/VecRegisterDynamic().

302:    Not Collective

304:    Level: advanced

306: .keywords: Vec, register, destroy
307: .seealso: VecRegister(), VecRegisterAll(), VecSerializeRegisterDestroy(), VecRegisterDynamic()
308: @*/
309: int VecRegisterDestroy(void)
310: {

314:   if (VecList != PETSC_NULL) {
315:     PetscFListDestroy(&VecList);
316:     VecList = PETSC_NULL;
317:   }
318:   VecRegisterAllCalled = PETSC_FALSE;
319:   return(0);
320: }

322: #undef __FUNCT__  
324: /*@C
325:   VecSerializeRegisterDestroy - Frees the list of serialization routines for
326:   vectors that were registered by VecSerializeRegister().

328:   Not collective

330:   Level: advanced

332: .keywords: Vec, vector, register, destroy
333: .seealso: VecSerializeRegisterAll()
334: @*/
335: int VecSerializeRegisterDestroy()
336: {

340:   if (VecSerializeList != PETSC_NULL) {
341:     PetscFListDestroy(&VecSerializeList);
342:     VecSerializeList = PETSC_NULL;
343:   }
344:   VecSerializeRegisterAllCalled = PETSC_FALSE;
345:   return(0);
346: }