xref: /petsc/src/sys/objects/gcomm.c (revision 030f984af8d8bb4c203755d35bded3c05b3d83ce)
1 
2 /*
3      Provides utility routines for manulating any type of PETSc object.
4 */
5 #include <petsc/private/petscimpl.h>  /*I   "petscsys.h"    I*/
6 
7 /*@C
8    PetscObjectComm - Gets the MPI communicator for any PetscObject   regardless of the type.
9 
10    Not Collective
11 
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,...);
16 
17    Output Parameter:
18 .  comm - the MPI communicator or MPI_COMM_NULL if object is not valid
19 
20    Level: advanced
21 
22    Notes:
23     Never use this in the form
24 $       comm = PetscObjectComm((PetscObject)obj);
25         instead use PetscObjectGetComm()
26 
27 .seealso: PetscObjectGetComm()
28 @*/
29 MPI_Comm  PetscObjectComm(PetscObject obj)
30 {
31   if (!obj) return MPI_COMM_NULL;
32   return obj->comm;
33 }
34 
35 /*@C
36    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
37    regardless of the type.
38 
39    Not Collective
40 
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);
45 
46    Output Parameter:
47 .  comm - the MPI communicator
48 
49    Level: advanced
50 
51 .seealso: PetscObjectComm()
52 @*/
53 PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
54 {
55   PetscErrorCode ierr;
56 
57   PetscFunctionBegin;
58   PetscValidHeader(obj,1);
59   PetscValidPointer(comm,2);
60   if (obj->bops->getcomm) {
61     ierr = obj->bops->getcomm(obj,comm);CHKERRQ(ierr);
62   } else *comm = obj->comm;
63   PetscFunctionReturn(0);
64 }
65 
66 /*@
67    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use
68 
69    Not Collective
70 
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);
75 
76    Output Parameter:
77 .   tab - the number of tabs
78 
79    Level: developer
80 
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 heirarchy of objects
84       is very clear.
85 
86 .seealso:  PetscObjectIncrementTabLevel()
87 
88 @*/
89 PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
90 {
91   PetscFunctionBegin;
92   PetscValidHeader(obj,1);
93   *tab = obj->tablevel;
94   PetscFunctionReturn(0);
95 }
96 
97 /*@
98    PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use
99 
100    Not Collective
101 
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
107 
108    Level: developer
109 
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 heirarchy of objects
113       is very clear.
114 
115 .seealso:  PetscObjectIncrementTabLevel()
116 @*/
117 PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
118 {
119   PetscFunctionBegin;
120   PetscValidHeader(obj,1);
121   obj->tablevel = tab;
122   PetscFunctionReturn(0);
123 }
124 
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.
128 
129    Not Collective
130 
131    Input Parameter:
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
135 
136    Level: developer
137 
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 heirarchy of objects
141       is very clear.
142 
143 .seealso:   PetscObjectSetTabLevel(),  PetscObjectGetTabLevel()
144 
145 @*/
146 PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
147 {
148 
149   PetscFunctionBegin;
150   PetscValidHeader(obj,1);
151   if (oldobj) obj->tablevel = oldobj->tablevel + tab;
152   else obj->tablevel = tab;
153   PetscFunctionReturn(0);
154 }
155