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