Actual source code: mapreg.c

  1: #define PETSCVEC_DLL
 2:  #include vecimpl.h

  4: PetscFList PetscMapList                       = PETSC_NULL;
  5: PetscTruth PetscMapRegisterAllCalled          = PETSC_FALSE;

  9: /*@C
 10:   PetscMapSetType - Builds a map, for a particular map implementation.

 12:   Collective on PetscMap

 14:   Input Parameters:
 15: + map    - The PetscMap object
 16: - method - The name of the map type

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

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

 25:   Level: intermediate

 27: .keywords: map, set, type
 28: .seealso PetscMapGetType(), PetscMapCreate()
 29: @*/
 30: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapSetType(PetscMap map, PetscMapType method)
 31: {
 32:   PetscErrorCode (*r)(PetscMap);
 33:   PetscTruth match;

 38:   PetscTypeCompare((PetscObject) map, method, &match);
 39:   if (match) return(0);

 41:   /* Get the function pointers for the method requested */
 42:   if (!PetscMapRegisterAllCalled) {
 43:     PetscMapRegisterAll(PETSC_NULL);
 44:   }
 45:   PetscFListFind(map->comm, PetscMapList, method, (void (**)(void)) &r);
 46:   if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown map type: %s", method);
 47:   if (map->ops->destroy) {
 48:     (*map->ops->destroy)(map);
 49:   }
 50:   (*r)(map);
 51:   PetscObjectChangeTypeName((PetscObject) map, method);
 52:   return(0);
 53: }

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

 60:   Not collective

 62:   Input Parameter:
 63: . map  - The map

 65:   Output Parameter:
 66: . type - The map type name

 68:   Level: intermediate

 70: .keywords: map, get, type, name
 71: .seealso PetscMapSetType(), PetscMapCreate()
 72: @*/
 73: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapGetType(PetscMap map, PetscMapType *type)
 74: {

 80:   if (!PetscMapRegisterAllCalled) {
 81:     PetscMapRegisterAll(PETSC_NULL);
 82:   }
 83:   *type = map->type_name;
 84:   return(0);
 85: }

 87: /*--------------------------------------------------------------------------------------------------------------------*/
 88: /*MC
 89:   PetscMapRegisterDynamic - Adds a new map component implementation

 91:   Synopsis:
 92:   PetscErrorCode PetscMapRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(PetscMap))

 94:   Not Collective

 96:   Input Parameters:
 97: + name        - The name of a new user-defined creation routine
 98: . path        - The path (either absolute or relative) of the library containing this routine
 99: . func_name   - The name of routine to create method context
100: - create_func - The creation routine itself

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

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

107:   Sample usage:
108: .vb
109:     PetscMapRegisterDynamic("my_map","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscMapCreate", MyPetscMapCreate);
110: .ve

112:   Then, your map type can be chosen with the procedural interface via
113: .vb
114:     PetscMapCreate(MPI_Comm, PetscMap *);
115:     PetscMapSetType(PetscMap,"my_map_name");
116: .ve
117:    or at runtime via the option
118: .vb
119:     -map_type my_map_name
120: .ve

122:   Note: $PETSC_ARCH  occuring in pathname will be replaced with appropriate values.

124:   Level: advanced

126: .keywords: PetscMap, register
127: .seealso: PetscMapRegisterAll(), PetscMapRegisterDestroy()
128: M*/

132: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(PetscMap))
133: {
134:   char fullname[PETSC_MAX_PATH_LEN];

138:   PetscStrcpy(fullname, path);
139:   PetscStrcat(fullname, ":");
140:   PetscStrcat(fullname, name);
141:   PetscFListAdd(&PetscMapList, sname, fullname, (void (*)(void)) function);
142:   return(0);
143: }

145: /*--------------------------------------------------------------------------------------------------------------------*/
148: /*@C
149:   PetscMapRegisterDestroy - Frees the list of PetscMap methods that were registered by PetscMapRegister().

151:   Not collective

153:   Level: advanced

155: .keywords: map, register, destroy
156: .seealso: PetscMapRegister(), PetscMapRegisterAll()
157: @*/
158: PetscErrorCode PETSCVEC_DLLEXPORT PetscMapRegisterDestroy()
159: {

163:   if (PetscMapList) {
164:     PetscFListDestroy(&PetscMapList);
165:     PetscMapList = PETSC_NULL;
166:   }
167:   PetscMapRegisterAllCalled = PETSC_FALSE;
168:   return(0);
169: }