Actual source code: aoreg.c

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

 5:  #include src/dm/ao/aoimpl.h

  7: PetscFList AOSerializeList              = 0;
  8: int        AOSerializeRegisterAllCalled = 0;

 10: #undef __FUNCT__  
 12: /*@C
 13:   AOSetSerializeType - Sets the serialization method for the application ordering.

 15:   Collective on AO

 17:   Input Parameters:
 18: + ao     - The AO context
 19: - method - A known method

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

 25:    Notes:
 26:    See "petsc/include/petscao.h" for available methods (for instance)
 27: +  AO_SER_DEBUG_BINARY - Debugging ordering to binary file
 28: -  AO_SER_BASIC_BINARY - Scalable ordering to binary file


 31:    Level: intermediate

 33: .keywords: AO, set, type, serialization
 34: @*/
 35: int AOSetSerializeType(AO ao, AOSerializeType method)
 36: {
 37:   int      (*r)(MPI_Comm, AO *, PetscViewer, PetscTruth);
 38:   PetscTruth match;
 39:   int        ierr;

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

 46:   /* Get the function pointers for the method requested but do not call */
 47:   if (!AOSerializeRegisterAllCalled) {
 48:     AOSerializeRegisterAll(PETSC_NULL);
 49:   }
 50:   PetscFListFind(ao->comm, AOSerializeList, method, (void (**)(void)) &r);
 51:   if (!r) {
 52:     SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
 53:   }

 55:   PetscObjectChangeSerializeName((PetscObject) ao, method);
 56:   return(0);
 57: }

 59: /*MC
 60:   AOSerializeRegister - Adds a serialization method to the application ordering package.

 62:   Synopsis:

 64:   AOSerializeRegister(char *serialize_name, char *path, char *serialize_func_name,
 65:                       int (*serialize_func)(MPI_Comm, AO *, PetscViewer, PetscTruth))

 67:   Not Collective

 69:   Input Parameters:
 70: + serialize_name      - The name of a new user-defined serialization routine
 71: . path                - The path (either absolute or relative) of the library containing this routine
 72: . serialize_func_name - The name of routine to create method context
 73: - serialize_func      - The serialization routine itself

 75:    Notes:
 76:    AOSerializeRegister() may be called multiple times to add several user-defined solvers.

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

 80:    Sample usage:
 81: .vb
 82:    AOSerializeRegister("my_store", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyStoreFunc", MyStoreFunc);
 83: .ve

 85:    Then, your serialization can be chosen with the procedural interface via
 86: $     AOSetSerializeType(ao, "my_store")
 87:    or at runtime via the option
 88: $     -ao_serialize_type my_store

 90:    Level: advanced

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

 94: .keywords: AO, register

 96: .seealso: AOSerializeRegisterAll(), AOSerializeRegisterDestroy()
 97: M*/
 98: #undef __FUNCT__  
100: int AOSerializeRegister_Private(const char *sname,const char *path,const char *name,int (*function)(MPI_Comm, AO *, PetscViewer, PetscTruth))
101: {
102:   char fullname[256];
103:   int  ierr;

106:   PetscStrcpy(fullname, path);
107:   PetscStrcat(fullname, ":");
108:   PetscStrcat(fullname, name);
109:   PetscFListAdd(&AOSerializeList, sname, fullname, (void (*)(void)) function);
110:   return(0);
111: }

113: /*-------------------------------------------------------------------------------------------------------------------*/
114: #undef __FUNCT__  
116: /*@C
117:    AOSerializeRegisterDestroy - Frees the list of serialization routines for
118:    application orderings that were registered by PetscFListAdd().

120:    Not Collective

122:    Level: advanced

124: .keywords: AO, application ordering, register, destroy

126: .seealso: AOSerializeRegisterAll(), AORegisterAll()
127: @*/
128: int AOSerializeRegisterDestroy(void)
129: {

133:   if (AOSerializeList) {
134:     PetscFListDestroy(&AOSerializeList);
135:     AOSerializeList = PETSC_NULL;
136:   }
137:   AOSerializeRegisterAllCalled = 0;
138:   return(0);
139: }