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 vecimpl.h

  7: PetscFList PetscMapList                       = PETSC_NULL;
  8: PetscTruth PetscMapRegisterAllCalled          = 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, MAP_MPI).

 28:   Level: intermediate

 30: .keywords: map, set, type
 31: .seealso PetscMapGetType(), PetscMapCreate()
 32: @*/
 33: int PetscMapSetType(PetscMap map, const 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: }

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

 65:   Not collective

 67:   Input Parameter:
 68: . map  - The map

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

 73:   Level: intermediate

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

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

 92: /*--------------------------------------------------------------------------------------------------------------------*/
 93: /*MC
 94:   PetscMapRegisterDynamic - Adds a new map component implementation

 96:   Synopsis:
 97:   PetscMapRegisterDynamic(char *name, char *path, char *func_name, int (*create_func)(PetscMap))

 99:   Not Collective

101:   Input Parameters:
102: + name        - The name of a new user-defined creation routine
103: . path        - The path (either absolute or relative) of the library containing this routine
104: . func_name   - The name of routine to create method context
105: - create_func - The creation routine itself

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

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

112:   Sample usage:
113: .vb
114:     PetscMapRegisterDynamic("my_map","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscMapCreate", MyPetscMapCreate);
115: .ve

117:   Then, your map type can be chosen with the procedural interface via
118: .vb
119:     PetscMapCreate(MPI_Comm, PetscMap *);
120:     PetscMapSetType(PetscMap,"my_map_name");
121: .ve
122:    or at runtime via the option
123: .vb
124:     -map_type my_map_name
125: .ve

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

129:   Level: advanced

131: .keywords: PetscMap, register
132: .seealso: PetscMapRegisterAll(), PetscMapRegisterDestroy()
133: M*/

137: int PetscMapRegister(const char sname[], const char path[], const char name[], int (*function)(PetscMap))
138: {
139:   char fullname[PETSC_MAX_PATH_LEN];
140:   int  ierr;

143:   PetscStrcpy(fullname, path);
144:   PetscStrcat(fullname, ":");
145:   PetscStrcat(fullname, name);
146:   PetscFListAdd(&PetscMapList, sname, fullname, (void (*)(void)) function);
147:   return(0);
148: }

150: /*--------------------------------------------------------------------------------------------------------------------*/
153: /*@C
154:   PetscMapRegisterDestroy - Frees the list of PetscMap methods that were registered by PetscMapRegister().

156:   Not collective

158:   Level: advanced

160: .keywords: map, register, destroy
161: .seealso: PetscMapRegister(), PetscMapRegisterAll()
162: @*/
163: int PetscMapRegisterDestroy()
164: {

168:   if (PetscMapList != PETSC_NULL) {
169:     PetscFListDestroy(&PetscMapList);
170:     PetscMapList = PETSC_NULL;
171:   }
172:   PetscMapRegisterAllCalled = PETSC_FALSE;
173:   return(0);
174: }