xref: /petsc/src/sys/objects/gcomm.c (revision 6aad120caa16b1027d343a5f30f73d01448e4dc0)
17d0a6c19SBarry Smith 
2e5c89e4eSSatish Balay /*
3e5c89e4eSSatish Balay      Provides utility routines for manulating any type of PETSc object.
4e5c89e4eSSatish Balay */
5af0996ceSBarry Smith #include <petsc/private/petscimpl.h>  /*I   "petscsys.h"    I*/
6e5c89e4eSSatish Balay 
7ce94432eSBarry Smith /*@C
8ce94432eSBarry Smith    PetscObjectComm - Gets the MPI communicator for any PetscObject   regardless of the type.
9ce94432eSBarry Smith 
10ce94432eSBarry Smith    Not Collective
11ce94432eSBarry Smith 
12ce94432eSBarry Smith    Input Parameter:
13ce94432eSBarry Smith .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
14ce94432eSBarry Smith          cast with a (PetscObject), for example,
15ce94432eSBarry Smith          SETERRQ(PetscObjectComm((PetscObject)mat,...);
16ce94432eSBarry Smith 
17ce94432eSBarry Smith    Output Parameter:
18ce94432eSBarry Smith .  comm - the MPI communicator or MPI_COMM_NULL if object is not valid
19ce94432eSBarry Smith 
20ce94432eSBarry Smith    Level: advanced
21ce94432eSBarry Smith 
2295452b02SPatrick Sanan    Notes:
2395452b02SPatrick Sanan     Never use this in the form
24ce94432eSBarry Smith $       comm = PetscObjectComm((PetscObject)obj);
25ce94432eSBarry Smith         instead use PetscObjectGetComm()
26ce94432eSBarry Smith 
27ce94432eSBarry Smith .seealso: PetscObjectGetComm()
28ce94432eSBarry Smith @*/
29ce94432eSBarry Smith MPI_Comm  PetscObjectComm(PetscObject obj)
30ce94432eSBarry Smith {
315f80ce2aSJacob Faibussowitsch   return obj ? obj->comm : MPI_COMM_NULL;
32ce94432eSBarry Smith }
33ce94432eSBarry Smith 
34e5c89e4eSSatish Balay /*@C
35e5c89e4eSSatish Balay    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
36e5c89e4eSSatish Balay    regardless of the type.
37e5c89e4eSSatish Balay 
38e5c89e4eSSatish Balay    Not Collective
39e5c89e4eSSatish Balay 
40e5c89e4eSSatish Balay    Input Parameter:
41e5c89e4eSSatish Balay .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
42e5c89e4eSSatish Balay          cast with a (PetscObject), for example,
43e5c89e4eSSatish Balay          PetscObjectGetComm((PetscObject)mat,&comm);
44e5c89e4eSSatish Balay 
45e5c89e4eSSatish Balay    Output Parameter:
46e5c89e4eSSatish Balay .  comm - the MPI communicator
47e5c89e4eSSatish Balay 
48e5c89e4eSSatish Balay    Level: advanced
49e5c89e4eSSatish Balay 
50ce94432eSBarry Smith .seealso: PetscObjectComm()
51e5c89e4eSSatish Balay @*/
527087cfbeSBarry Smith PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
53e5c89e4eSSatish Balay {
54e5c89e4eSSatish Balay   PetscFunctionBegin;
553cfa8680SLisandro Dalcin   PetscValidHeader(obj,1);
563cfa8680SLisandro Dalcin   PetscValidPointer(comm,2);
579566063dSJacob Faibussowitsch   if (obj->bops->getcomm) PetscCall(obj->bops->getcomm(obj,comm));
585f80ce2aSJacob Faibussowitsch   else *comm = obj->comm;
59e5c89e4eSSatish Balay   PetscFunctionReturn(0);
60e5c89e4eSSatish Balay }
61e5c89e4eSSatish Balay 
62cbf1b8bfSBarry Smith /*@
631cee3971SBarry Smith    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use
64e5c89e4eSSatish Balay 
651cee3971SBarry Smith    Not Collective
661cee3971SBarry Smith 
671cee3971SBarry Smith    Input Parameter:
681cee3971SBarry Smith .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
691cee3971SBarry Smith          cast with a (PetscObject), for example,
701cee3971SBarry Smith          PetscObjectGetComm((PetscObject)mat,&comm);
711cee3971SBarry Smith 
721cee3971SBarry Smith    Output Parameter:
731cee3971SBarry Smith .   tab - the number of tabs
741cee3971SBarry Smith 
751cee3971SBarry Smith    Level: developer
761cee3971SBarry Smith 
7795452b02SPatrick Sanan     Notes:
78*6aad120cSJose E. Roman     this is used to manage the output from options that are embedded in other objects. For example
79a5b23f4aSJose E. Roman       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
801cee3971SBarry Smith       is very clear.
811cee3971SBarry Smith 
821cee3971SBarry Smith .seealso:  PetscObjectIncrementTabLevel()
831cee3971SBarry Smith 
841cee3971SBarry Smith @*/
857087cfbeSBarry Smith PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
861cee3971SBarry Smith {
871cee3971SBarry Smith   PetscFunctionBegin;
881cee3971SBarry Smith   PetscValidHeader(obj,1);
895f80ce2aSJacob Faibussowitsch   PetscValidIntPointer(tab,2);
901cee3971SBarry Smith   *tab = obj->tablevel;
911cee3971SBarry Smith   PetscFunctionReturn(0);
921cee3971SBarry Smith }
931cee3971SBarry Smith 
94da35de2aSMatthew G Knepley /*@
95da35de2aSMatthew G Knepley    PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use
96da35de2aSMatthew G Knepley 
97da35de2aSMatthew G Knepley    Not Collective
98da35de2aSMatthew G Knepley 
99da35de2aSMatthew G Knepley    Input Parameters:
100da35de2aSMatthew G Knepley +  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
101da35de2aSMatthew G Knepley          cast with a (PetscObject), for example,
102da35de2aSMatthew G Knepley          PetscObjectGetComm((PetscObject)mat,&comm);
103da35de2aSMatthew G Knepley -   tab - the number of tabs
104da35de2aSMatthew G Knepley 
105da35de2aSMatthew G Knepley    Level: developer
106da35de2aSMatthew G Knepley 
10795452b02SPatrick Sanan     Notes:
108*6aad120cSJose E. Roman     this is used to manage the output from options that are embedded in other objects. For example
109a5b23f4aSJose E. Roman       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
110da35de2aSMatthew G Knepley       is very clear.
111da35de2aSMatthew G Knepley 
112da35de2aSMatthew G Knepley .seealso:  PetscObjectIncrementTabLevel()
113da35de2aSMatthew G Knepley @*/
114da35de2aSMatthew G Knepley PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
115da35de2aSMatthew G Knepley {
116da35de2aSMatthew G Knepley   PetscFunctionBegin;
117da35de2aSMatthew G Knepley   PetscValidHeader(obj,1);
118da35de2aSMatthew G Knepley   obj->tablevel = tab;
119da35de2aSMatthew G Knepley   PetscFunctionReturn(0);
120da35de2aSMatthew G Knepley }
121da35de2aSMatthew G Knepley 
122cbf1b8bfSBarry Smith /*@
1231cee3971SBarry Smith    PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on
1241cee3971SBarry Smith          the tablevel of another object. This should be called immediately after the object is created.
1251cee3971SBarry Smith 
1261cee3971SBarry Smith    Not Collective
1271cee3971SBarry Smith 
128d8d19677SJose E. Roman    Input Parameters:
1291cee3971SBarry Smith +  obj - any PETSc object where we are changing the tab
1301cee3971SBarry Smith .  oldobj - the object providing the tab
1311cee3971SBarry Smith -  tab - the increment that is added to the old objects tab
1321cee3971SBarry Smith 
1331cee3971SBarry Smith    Level: developer
1341cee3971SBarry Smith 
13595452b02SPatrick Sanan     Notes:
136*6aad120cSJose E. Roman     this is used to manage the output from options that are embedded in other objects. For example
137a5b23f4aSJose E. Roman       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
1381cee3971SBarry Smith       is very clear.
1391cee3971SBarry Smith 
140acdf4722SStefano Zampini .seealso:   PetscObjectSetTabLevel(),  PetscObjectGetTabLevel()
1411cee3971SBarry Smith 
1421cee3971SBarry Smith @*/
1437087cfbeSBarry Smith PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
1441cee3971SBarry Smith {
1451cee3971SBarry Smith   PetscFunctionBegin;
1461cee3971SBarry Smith   PetscValidHeader(obj,1);
1475f80ce2aSJacob Faibussowitsch   if (oldobj) PetscValidHeader(oldobj,2);
1485f80ce2aSJacob Faibussowitsch   obj->tablevel = (oldobj ? oldobj->tablevel : 0)+tab;
1491cee3971SBarry Smith   PetscFunctionReturn(0);
1501cee3971SBarry Smith }
151