Actual source code: gcomm.c


  2: /*
  3:      Provides utility routines for manulating any type of PETSc object.
  4: */
  5: #include <petsc/private/petscimpl.h>

  7: /*@C
  8:    PetscObjectComm - Gets the MPI communicator for any PetscObject   regardless of the type.

 10:    Not Collective

 12:    Input Parameter:
 13: .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
 14:          cast with a (PetscObject), for example,
 15:          SETERRQ(PetscObjectComm((PetscObject)mat,...);

 17:    Output Parameter:
 18: .  comm - the MPI communicator or MPI_COMM_NULL if object is not valid

 20:    Level: advanced

 22:    Notes:
 23:     Never use this in the form
 24: $       comm = PetscObjectComm((PetscObject)obj);
 25:         instead use PetscObjectGetComm()

 27: .seealso: PetscObjectGetComm()
 28: @*/
 29: MPI_Comm  PetscObjectComm(PetscObject obj)
 30: {
 31:   if (!obj) return MPI_COMM_NULL;
 32:   return obj->comm;
 33: }

 35: /*@C
 36:    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
 37:    regardless of the type.

 39:    Not Collective

 41:    Input Parameter:
 42: .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
 43:          cast with a (PetscObject), for example,
 44:          PetscObjectGetComm((PetscObject)mat,&comm);

 46:    Output Parameter:
 47: .  comm - the MPI communicator

 49:    Level: advanced

 51: .seealso: PetscObjectComm()
 52: @*/
 53: PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
 54: {

 60:   if (obj->bops->getcomm) {
 61:     obj->bops->getcomm(obj,comm);
 62:   } else *comm = obj->comm;
 63:   return(0);
 64: }

 66: /*@
 67:    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use

 69:    Not Collective

 71:    Input Parameter:
 72: .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
 73:          cast with a (PetscObject), for example,
 74:          PetscObjectGetComm((PetscObject)mat,&comm);

 76:    Output Parameter:
 77: .   tab - the number of tabs

 79:    Level: developer

 81:     Notes:
 82:     this is used to manage the output from options that are imbedded in other objects. For example
 83:       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
 84:       is very clear.

 86: .seealso:  PetscObjectIncrementTabLevel()

 88: @*/
 89: PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
 90: {
 93:   *tab = obj->tablevel;
 94:   return(0);
 95: }

 97: /*@
 98:    PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use

100:    Not Collective

102:    Input Parameters:
103: +  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
104:          cast with a (PetscObject), for example,
105:          PetscObjectGetComm((PetscObject)mat,&comm);
106: -   tab - the number of tabs

108:    Level: developer

110:     Notes:
111:     this is used to manage the output from options that are imbedded in other objects. For example
112:       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
113:       is very clear.

115: .seealso:  PetscObjectIncrementTabLevel()
116: @*/
117: PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
118: {
121:   obj->tablevel = tab;
122:   return(0);
123: }

125: /*@
126:    PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on
127:          the tablevel of another object. This should be called immediately after the object is created.

129:    Not Collective

131:    Input Parameters:
132: +  obj - any PETSc object where we are changing the tab
133: .  oldobj - the object providing the tab
134: -  tab - the increment that is added to the old objects tab

136:    Level: developer

138:     Notes:
139:     this is used to manage the output from options that are imbedded in other objects. For example
140:       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
141:       is very clear.

143: .seealso:   PetscObjectSetTabLevel(),  PetscObjectGetTabLevel()

145: @*/
146: PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
147: {

151:   if (oldobj) obj->tablevel = oldobj->tablevel + tab;
152:   else obj->tablevel = tab;
153:   return(0);
154: }