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()

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

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

     40:    Not Collective

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

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

     50:    Level: advanced

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

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

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

     71:    Not Collective

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

     78:    Output Parameter:
     79: .   tab - the number of tabs

     81:    Level: developer

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

     88: .seealso:  PetscObjectIncrementTabLevel()

     90: @*/
     91: PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
     92: {
     95:   *tab = obj->tablevel;
     96:   return(0);
     97: }

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

    102:    Not Collective

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

    110:    Level: developer

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

    117: .seealso:  PetscObjectIncrementTabLevel()
    118: @*/
    119: PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
    120: {
    123:   obj->tablevel = tab;
    124:   return(0);
    125: }

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

    131:    Not Collective

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

    139:    Level: developer

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

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

    148: @*/
    149: PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
    150: {

    154:   if (oldobj) obj->tablevel = oldobj->tablevel + tab;
    155:   else obj->tablevel = tab;
    156:   return(0);
    157: }