Actual source code: aoreg.c

petsc-3.3-p7 2013-05-11
  2: #include <../src/dm/ao/aoimpl.h>    /*I "petscao.h"  I*/

  4: PetscFList AOList                       = PETSC_NULL;
  5: PetscBool  AORegisterAllCalled          = PETSC_FALSE;

  9: /*@C
 10:   AOSetType - Builds an application ordering for a particular implementation.

 12:   Collective on AO

 14:   Input Parameters:
 15: + ao    - The AO object
 16: - method - The name of the AO type

 18:   Options Database Key:
 19: . -ao_type <type> - Sets the AO type; use -help for a list of available types

 21:   Notes:
 22:   See "petsc/include/petscao.h" for available AO types (for instance, AOBASIC and AOMEMORYSCALABLE).

 24:   Level: intermediate

 26: .keywords: ao, set, type
 27: .seealso: AOGetType(), AOCreate()
 28: @*/
 29: PetscErrorCode  AOSetType(AO ao, const AOType method)
 30: {
 31:   PetscErrorCode (*r)(AO);
 32:   PetscBool      match;

 37:   PetscObjectTypeCompare((PetscObject)ao, method, &match);
 38:   if (match) return(0);

 40:   if (!AORegisterAllCalled) {AORegisterAll(PETSC_NULL);}
 41:   PetscFListFind(AOList, ((PetscObject)ao)->comm, method,PETSC_TRUE,(void (**)(void)) &r);
 42:   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown AO type: %s", method);
 43:   if (ao->ops->destroy) {
 44:     (*ao->ops->destroy)(ao);
 45:     ao->ops->destroy = PETSC_NULL;
 46:   }
 47: 
 48:   (*r)(ao);
 49:   return(0);
 50: }

 54: /*@C
 55:   AOGetType - Gets the AO type name (as a string) from the AO.

 57:   Not Collective

 59:   Input Parameter:
 60: . ao  - The vector

 62:   Output Parameter:
 63: . type - The AO type name

 65:   Level: intermediate

 67: .keywords: ao, get, type, name
 68: .seealso: AOSetType(), AOCreate()
 69: @*/
 70: PetscErrorCode  AOGetType(AO ao, const AOType *type)
 71: {

 77:   if (!AORegisterAllCalled) {
 78:     AORegisterAll(PETSC_NULL);
 79:   }
 80:   *type = ((PetscObject)ao)->type_name;
 81:   return(0);
 82: }


 85: /*--------------------------------------------------------------------------------------------------------------------*/

 89: /*@C
 90:   AORegister - See AORegisterDynamic()

 92:   Level: advanced
 93: @*/
 94: PetscErrorCode  AORegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(AO))
 95: {
 96:   char fullname[PETSC_MAX_PATH_LEN];

100:   PetscStrcpy(fullname, path);
101:   PetscStrcat(fullname, ":");
102:   PetscStrcat(fullname, name);
103:   PetscFListAdd(&AOList, sname, fullname, (void (*)(void)) function);
104:   return(0);
105: }


108: /*--------------------------------------------------------------------------------------------------------------------*/
111: /*@C
112:    AORegisterDestroy - Frees the list of AO methods that were registered by AORegister()/AORegisterDynamic().

114:    Not Collective

116:    Level: advanced

118: .keywords: AO, register, destroy
119: .seealso: AORegister(), AORegisterAll(), AORegisterDynamic()
120: @*/
121: PetscErrorCode  AORegisterDestroy(void)
122: {

126:   PetscFListDestroy(&AOList);
127:   AORegisterAllCalled = PETSC_FALSE;
128:   return(0);
129: }