xref: /petsc/src/sys/objects/gcomm.c (revision 5b6bfdb9644f185dbf5e5a09b808ec241507e1e7)
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: Never use this in the form
23 $       comm = PetscObjectComm((PetscObject)obj);
24         instead use PetscObjectGetComm()
25 
26    Concepts: communicator^getting from object
27    Concepts: MPI communicator^getting from object
28 
29 .seealso: PetscObjectGetComm()
30 @*/
31 MPI_Comm  PetscObjectComm(PetscObject obj)
32 {
33   if (!obj) return MPI_COMM_NULL;
34   return obj->comm;
35 }
36 
37 /*@C
38    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
39    regardless of the type.
40 
41    Not Collective
42 
43    Input Parameter:
44 .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
45          cast with a (PetscObject), for example,
46          PetscObjectGetComm((PetscObject)mat,&comm);
47 
48    Output Parameter:
49 .  comm - the MPI communicator
50 
51    Level: advanced
52 
53    Concepts: communicator^getting from object
54    Concepts: MPI communicator^getting from object
55 
56 .seealso: PetscObjectComm()
57 @*/
58 PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
59 {
60   PetscErrorCode ierr;
61 
62   PetscFunctionBegin;
63   PetscValidHeader(obj,1);
64   PetscValidPointer(comm,2);
65   if (obj->bops->getcomm) {
66     ierr = obj->bops->getcomm(obj,comm);CHKERRQ(ierr);
67   } else *comm = obj->comm;
68   PetscFunctionReturn(0);
69 }
70 
71 /*@
72    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use
73 
74    Not Collective
75 
76    Input Parameter:
77 .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
78          cast with a (PetscObject), for example,
79          PetscObjectGetComm((PetscObject)mat,&comm);
80 
81    Output Parameter:
82 .   tab - the number of tabs
83 
84    Level: developer
85 
86     Notes: this is used to manage the output from options that are imbedded in other objects. For example
87       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
88       is very clear.
89 
90 .seealso:  PetscObjectIncrementTabLevel()
91 
92 @*/
93 PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
94 {
95   PetscFunctionBegin;
96   PetscValidHeader(obj,1);
97   *tab = obj->tablevel;
98   PetscFunctionReturn(0);
99 }
100 
101 /*@
102    PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use
103 
104    Not Collective
105 
106    Input Parameters:
107 +  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
108          cast with a (PetscObject), for example,
109          PetscObjectGetComm((PetscObject)mat,&comm);
110 -   tab - the number of tabs
111 
112    Level: developer
113 
114     Notes: this is used to manage the output from options that are imbedded in other objects. For example
115       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
116       is very clear.
117 
118 .seealso:  PetscObjectIncrementTabLevel()
119 @*/
120 PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
121 {
122   PetscFunctionBegin;
123   PetscValidHeader(obj,1);
124   obj->tablevel = tab;
125   PetscFunctionReturn(0);
126 }
127 
128 /*@
129    PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on
130          the tablevel of another object. This should be called immediately after the object is created.
131 
132    Not Collective
133 
134    Input Parameter:
135 +  obj - any PETSc object where we are changing the tab
136 .  oldobj - the object providing the tab
137 -  tab - the increment that is added to the old objects tab
138 
139 
140    Level: developer
141 
142     Notes: 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.
145 
146 .seealso:   PetscObjectSetLabLevel(),  PetscObjectGetTabLevel()
147 
148 @*/
149 PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
150 {
151 
152   PetscFunctionBegin;
153   PetscValidHeader(obj,1);
154   if (oldobj) obj->tablevel = oldobj->tablevel + tab;
155   else obj->tablevel = tab;
156   PetscFunctionReturn(0);
157 }
158