Date: 2022-08-02T03:13:22+00:00

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:   return obj ? obj->comm : MPI_COMM_NULL;
     32: }

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

     38:    Not Collective

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

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

     48:    Level: advanced

     50: .seealso: PetscObjectComm()
     51: @*/
     52: PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
     53: {
     56:   if (obj->bops->getcomm) obj->bops->getcomm(obj,comm);
     57:   else *comm = obj->comm;
     58:   return 0;
     59: }

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

     64:    Not Collective

     66:    Input Parameter:
     67: .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
     68:          cast with a (PetscObject), for example,
     69:          PetscObjectGetComm((PetscObject)mat,&comm);

     71:    Output Parameter:
     72: .   tab - the number of tabs

     74:    Level: developer

     76:     Notes:
     77:     this is used to manage the output from options that are embedded in other objects. For example
     78:       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
     79:       is very clear.

     81: .seealso:  PetscObjectIncrementTabLevel()

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

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

     95:    Not Collective

     97:    Input Parameters:
     98: +  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
     99:          cast with a (PetscObject), for example,
    100:          PetscObjectGetComm((PetscObject)mat,&comm);
    101: -   tab - the number of tabs

    103:    Level: developer

    105:     Notes:
    106:     this is used to manage the output from options that are embedded in other objects. For example
    107:       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
    108:       is very clear.

    110: .seealso:  PetscObjectIncrementTabLevel()
    111: @*/
    112: PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
    113: {
    115:   obj->tablevel = tab;
    116:   return 0;
    117: }

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

    123:    Not Collective

    125:    Input Parameters:
    126: +  obj - any PETSc object where we are changing the tab
    127: .  oldobj - the object providing the tab
    128: -  tab - the increment that is added to the old objects tab

    130:    Level: developer

    132:     Notes:
    133:     this is used to manage the output from options that are embedded in other objects. For example
    134:       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
    135:       is very clear.

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

    139: @*/
    140: PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
    141: {
    144:   obj->tablevel = (oldobj ? oldobj->tablevel : 0)+tab;
    145:   return 0;
    146: }