xref: /petsc/include/petscviewer.h (revision be7a6d03210faab0df8c3f3b720c976929326be8)
1 /*
2      PetscViewers are objects where other objects can be looked at or stored.
3 */
4 
5 #if !defined(__PETSCVIEWER_H)
6 #define __PETSCVIEWER_H
7 
8 #include <petscsys.h>
9 #include <petscviewertypes.h>
10 
11 PETSC_EXTERN PetscClassId PETSC_VIEWER_CLASSID;
12 
13 /*J
14     PetscViewerType - String with the name of a PETSc PETScViewer
15 
16    Level: beginner
17 
18 .seealso: PetscViewerSetType(), PetscViewer, PetscViewerRegister(), PetscViewerCreate()
19 J*/
20 typedef const char* PetscViewerType;
21 #define PETSCVIEWERSOCKET       "socket"
22 #define PETSCVIEWERASCII        "ascii"
23 #define PETSCVIEWERBINARY       "binary"
24 #define PETSCVIEWERSTRING       "string"
25 #define PETSCVIEWERDRAW         "draw"
26 #define PETSCVIEWERVU           "vu"
27 #define PETSCVIEWERMATHEMATICA  "mathematica"
28 #define PETSCVIEWERNETCDF       "netcdf"
29 #define PETSCVIEWERHDF5         "hdf5"
30 #define PETSCVIEWERVTK          "vtk"
31 #define PETSCVIEWERMATLAB       "matlab"
32 #define PETSCVIEWERAMS          "ams"
33 
34 PETSC_EXTERN PetscFunctionList PetscViewerList;
35 PETSC_EXTERN PetscErrorCode PetscViewerRegisterAll(void);
36 PETSC_EXTERN PetscErrorCode PetscViewerInitializePackage(void);
37 
38 PETSC_EXTERN PetscErrorCode PetscViewerRegister(const char[],PetscErrorCode (*)(PetscViewer));
39 
40 PETSC_EXTERN PetscErrorCode PetscViewerCreate(MPI_Comm,PetscViewer*);
41 PETSC_EXTERN PetscErrorCode PetscViewerSetFromOptions(PetscViewer);
42 PETSC_EXTERN PetscErrorCode PetscViewerASCIIOpenWithFILE(MPI_Comm,FILE*,PetscViewer*);
43 
44 PETSC_EXTERN PetscErrorCode PetscViewerASCIIOpen(MPI_Comm,const char[],PetscViewer*);
45 PETSC_EXTERN PetscErrorCode PetscViewerASCIISetFILE(PetscViewer,FILE*);
46 PETSC_EXTERN PetscErrorCode PetscViewerBinaryOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
47 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetFlowControl(PetscViewer,PetscInt*);
48 PETSC_EXTERN PetscErrorCode PetscViewerBinarySetFlowControl(PetscViewer,PetscInt);
49 PETSC_EXTERN PetscErrorCode PetscViewerBinarySetMPIIO(PetscViewer);
50 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetMPIIO(PetscViewer,PetscBool *);
51 #if defined(PETSC_HAVE_MPIIO)
52 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetMPIIODescriptor(PetscViewer,MPI_File*);
53 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetMPIIOOffset(PetscViewer,MPI_Offset*);
54 PETSC_EXTERN PetscErrorCode PetscViewerBinaryAddMPIIOOffset(PetscViewer,MPI_Offset);
55 #endif
56 
57 PETSC_EXTERN PetscErrorCode PetscViewerSocketOpen(MPI_Comm,const char[],int,PetscViewer*);
58 PETSC_EXTERN PetscErrorCode PetscViewerStringOpen(MPI_Comm,char[],PetscInt,PetscViewer*);
59 PETSC_EXTERN PetscErrorCode PetscViewerDrawOpen(MPI_Comm,const char[],const char[],int,int,int,int,PetscViewer*);
60 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaOpen(MPI_Comm, int, const char[], const char[], PetscViewer *);
61 PETSC_EXTERN PetscErrorCode PetscViewerSiloOpen(MPI_Comm, const char[], PetscViewer *);
62 PETSC_EXTERN PetscErrorCode PetscViewerMatlabOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
63 
64 PETSC_EXTERN PetscErrorCode PetscViewerGetType(PetscViewer,PetscViewerType*);
65 PETSC_EXTERN PetscErrorCode PetscViewerSetType(PetscViewer,PetscViewerType);
66 PETSC_EXTERN PetscErrorCode PetscViewerDestroy(PetscViewer*);
67 PETSC_EXTERN PetscErrorCode PetscViewerGetSingleton(PetscViewer,PetscViewer*);
68 PETSC_EXTERN PetscErrorCode PetscViewerRestoreSingleton(PetscViewer,PetscViewer*);
69 PETSC_EXTERN PetscErrorCode PetscViewerGetSubcomm(PetscViewer,MPI_Comm,PetscViewer*);
70 PETSC_EXTERN PetscErrorCode PetscViewerRestoreSubcomm(PetscViewer,MPI_Comm,PetscViewer*);
71 
72 PETSC_EXTERN PetscErrorCode PetscViewerSetUp(PetscViewer);
73 PETSC_EXTERN PetscErrorCode PetscViewerView(PetscViewer,PetscViewer);
74 
75 PETSC_EXTERN PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer,const char[]);
76 PETSC_EXTERN PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer,const char[]);
77 PETSC_EXTERN PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer,const char*[]);
78 
79 /*E
80     PetscViewerFormat - Way a viewer presents the object
81 
82    Level: beginner
83 
84    The values below are also listed in finclude/petscviewer.h. If another values is added below it
85    must also be added there.
86 
87 .seealso: PetscViewerSetFormat(), PetscViewer, PetscViewerType, PetscViewerPushFormat(), PetscViewerPopFormat()
88 E*/
89 typedef enum {
90   PETSC_VIEWER_DEFAULT,
91   PETSC_VIEWER_ASCII_MATLAB,
92   PETSC_VIEWER_ASCII_MATHEMATICA,
93   PETSC_VIEWER_ASCII_IMPL,
94   PETSC_VIEWER_ASCII_INFO,
95   PETSC_VIEWER_ASCII_INFO_DETAIL,
96   PETSC_VIEWER_ASCII_COMMON,
97   PETSC_VIEWER_ASCII_SYMMODU,
98   PETSC_VIEWER_ASCII_INDEX,
99   PETSC_VIEWER_ASCII_DENSE,
100   PETSC_VIEWER_ASCII_MATRIXMARKET,
101   PETSC_VIEWER_ASCII_VTK,
102   PETSC_VIEWER_ASCII_VTK_CELL,
103   PETSC_VIEWER_ASCII_VTK_COORDS,
104   PETSC_VIEWER_ASCII_PCICE,
105   PETSC_VIEWER_ASCII_PYTHON,
106   PETSC_VIEWER_ASCII_FACTOR_INFO,
107   PETSC_VIEWER_ASCII_LATEX,
108   PETSC_VIEWER_DRAW_BASIC,
109   PETSC_VIEWER_DRAW_LG,
110   PETSC_VIEWER_DRAW_CONTOUR,
111   PETSC_VIEWER_DRAW_PORTS,
112   PETSC_VIEWER_VTK_VTS,
113   PETSC_VIEWER_VTK_VTU,
114   PETSC_VIEWER_BINARY_MATLAB,
115   PETSC_VIEWER_NATIVE,
116   PETSC_VIEWER_NOFORMAT
117   } PetscViewerFormat;
118 PETSC_EXTERN const char *const PetscViewerFormats[];
119 
120 PETSC_EXTERN PetscErrorCode PetscViewerSetFormat(PetscViewer,PetscViewerFormat);
121 PETSC_EXTERN PetscErrorCode PetscViewerPushFormat(PetscViewer,PetscViewerFormat);
122 PETSC_EXTERN PetscErrorCode PetscViewerPopFormat(PetscViewer);
123 PETSC_EXTERN PetscErrorCode PetscViewerGetFormat(PetscViewer,PetscViewerFormat*);
124 PETSC_EXTERN PetscErrorCode PetscViewerFlush(PetscViewer);
125 
126 PETSC_EXTERN PetscErrorCode PetscOptionsGetViewer(MPI_Comm,const char[],const char[],PetscViewer*,PetscViewerFormat*,PetscBool*);
127 PETSC_EXTERN PetscErrorCode PetscOptionsViewer(const char[],const char[],const char[],PetscViewer*,PetscViewerFormat *,PetscBool *);
128 
129 /*
130    Operations explicit to a particular class of viewers
131 */
132 
133 PETSC_EXTERN PetscErrorCode PetscViewerASCIIGetPointer(PetscViewer,FILE**);
134 PETSC_EXTERN PetscErrorCode PetscViewerFileGetMode(PetscViewer,PetscFileMode*);
135 PETSC_EXTERN PetscErrorCode PetscViewerFileSetMode(PetscViewer,PetscFileMode);
136 PETSC_EXTERN PetscErrorCode PetscViewerASCIIPrintf(PetscViewer,const char[],...);
137 PETSC_EXTERN PetscErrorCode PetscViewerASCIISynchronizedPrintf(PetscViewer,const char[],...);
138 PETSC_EXTERN PetscErrorCode PetscViewerASCIISynchronizedAllow(PetscViewer,PetscBool);
139 PETSC_EXTERN PetscErrorCode PetscViewerASCIIPushTab(PetscViewer);
140 PETSC_EXTERN PetscErrorCode PetscViewerASCIIPopTab(PetscViewer);
141 PETSC_EXTERN PetscErrorCode PetscViewerASCIIUseTabs(PetscViewer,PetscBool );
142 PETSC_EXTERN PetscErrorCode PetscViewerASCIISetTab(PetscViewer,PetscInt);
143 PETSC_EXTERN PetscErrorCode PetscViewerASCIIGetTab(PetscViewer,PetscInt*);
144 PETSC_EXTERN PetscErrorCode PetscViewerASCIIAddTab(PetscViewer,PetscInt);
145 PETSC_EXTERN PetscErrorCode PetscViewerASCIISubtractTab(PetscViewer,PetscInt);
146 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetDescriptor(PetscViewer,int*);
147 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetInfoPointer(PetscViewer,FILE **);
148 PETSC_EXTERN PetscErrorCode PetscViewerBinaryRead(PetscViewer,void*,PetscInt,PetscDataType);
149 PETSC_EXTERN PetscErrorCode PetscViewerBinaryWrite(PetscViewer,void*,PetscInt,PetscDataType,PetscBool );
150 PETSC_EXTERN PetscErrorCode PetscViewerStringSPrintf(PetscViewer,const char[],...);
151 PETSC_EXTERN PetscErrorCode PetscViewerStringSetString(PetscViewer,char[],PetscInt);
152 PETSC_EXTERN PetscErrorCode PetscViewerDrawClear(PetscViewer);
153 PETSC_EXTERN PetscErrorCode PetscViewerDrawSetHold(PetscViewer,PetscBool);
154 PETSC_EXTERN PetscErrorCode PetscViewerDrawGetHold(PetscViewer,PetscBool*);
155 PETSC_EXTERN PetscErrorCode PetscViewerDrawSetPause(PetscViewer,PetscReal);
156 PETSC_EXTERN PetscErrorCode PetscViewerDrawGetPause(PetscViewer,PetscReal*);
157 PETSC_EXTERN PetscErrorCode PetscViewerDrawSetInfo(PetscViewer,const char[],const char[],int,int,int,int);
158 PETSC_EXTERN PetscErrorCode PetscViewerDrawResize(PetscViewer,int,int);
159 PETSC_EXTERN PetscErrorCode PetscViewerDrawSetBounds(PetscViewer,PetscInt,const PetscReal*);
160 PETSC_EXTERN PetscErrorCode PetscViewerDrawGetBounds(PetscViewer,PetscInt*,const PetscReal**);
161 PETSC_EXTERN PetscErrorCode PetscViewerSocketSetConnection(PetscViewer,const char[],int);
162 PETSC_EXTERN PetscErrorCode PetscViewerBinarySkipInfo(PetscViewer);
163 PETSC_EXTERN PetscErrorCode PetscViewerBinarySetSkipOptions(PetscViewer,PetscBool );
164 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetSkipOptions(PetscViewer,PetscBool *);
165 PETSC_EXTERN PetscErrorCode PetscViewerBinarySetSkipHeader(PetscViewer,PetscBool);
166 PETSC_EXTERN PetscErrorCode PetscViewerBinaryGetSkipHeader(PetscViewer,PetscBool*);
167 PETSC_EXTERN PetscErrorCode PetscViewerBinaryReadStringArray(PetscViewer,char***);
168 PETSC_EXTERN PetscErrorCode PetscViewerBinaryWriteStringArray(PetscViewer,char**);
169 
170 PETSC_EXTERN PetscErrorCode PetscViewerFileSetName(PetscViewer,const char[]);
171 PETSC_EXTERN PetscErrorCode PetscViewerFileGetName(PetscViewer,const char**);
172 
173 PETSC_EXTERN PetscErrorCode PetscViewerVUGetPointer(PetscViewer, FILE**);
174 PETSC_EXTERN PetscErrorCode PetscViewerVUSetVecSeen(PetscViewer, PetscBool );
175 PETSC_EXTERN PetscErrorCode PetscViewerVUGetVecSeen(PetscViewer, PetscBool  *);
176 PETSC_EXTERN PetscErrorCode PetscViewerVUPrintDeferred(PetscViewer, const char [], ...);
177 PETSC_EXTERN PetscErrorCode PetscViewerVUFlushDeferred(PetscViewer);
178 
179 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaInitializePackage(void);
180 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaFinalizePackage(void);
181 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaGetName(PetscViewer, const char **);
182 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaSetName(PetscViewer, const char []);
183 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaClearName(PetscViewer);
184 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaSkipPackets(PetscViewer, int);
185 
186 PETSC_EXTERN PetscErrorCode PetscViewerSiloGetName(PetscViewer, char **);
187 PETSC_EXTERN PetscErrorCode PetscViewerSiloSetName(PetscViewer, const char []);
188 PETSC_EXTERN PetscErrorCode PetscViewerSiloClearName(PetscViewer);
189 PETSC_EXTERN PetscErrorCode PetscViewerSiloGetMeshName(PetscViewer, char **);
190 PETSC_EXTERN PetscErrorCode PetscViewerSiloSetMeshName(PetscViewer, const char []);
191 PETSC_EXTERN PetscErrorCode PetscViewerSiloClearMeshName(PetscViewer);
192 
193 PETSC_EXTERN PetscErrorCode PetscViewerNetcdfOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
194 PETSC_EXTERN PetscErrorCode PetscViewerNetcdfGetID(PetscViewer, int *);
195 
196 typedef enum {PETSC_VTK_POINT_FIELD, PETSC_VTK_POINT_VECTOR_FIELD, PETSC_VTK_CELL_FIELD, PETSC_VTK_CELL_VECTOR_FIELD} PetscViewerVTKFieldType;
197 PETSC_EXTERN PetscErrorCode PetscViewerVTKAddField(PetscViewer,PetscObject,PetscErrorCode (*PetscViewerVTKWriteFunction)(PetscObject,PetscViewer),PetscViewerVTKFieldType,PetscObject);
198 PETSC_EXTERN PetscErrorCode PetscViewerVTKOpen(MPI_Comm,const char[],PetscFileMode,PetscViewer*);
199 
200 /*
201      These are all the default viewers that do not have to be explicitly opened
202 */
203 PETSC_EXTERN PetscViewer    PETSC_VIEWER_STDOUT_(MPI_Comm);
204 PETSC_EXTERN PetscErrorCode PetscViewerASCIIGetStdout(MPI_Comm,PetscViewer*);
205 PETSC_EXTERN PetscViewer    PETSC_VIEWER_STDERR_(MPI_Comm);
206 PETSC_EXTERN PetscErrorCode PetscViewerASCIIGetStderr(MPI_Comm,PetscViewer*);
207 PETSC_EXTERN PetscViewer    PETSC_VIEWER_DRAW_(MPI_Comm);
208 PETSC_EXTERN PetscViewer    PETSC_VIEWER_SOCKET_(MPI_Comm);
209 PETSC_EXTERN PetscViewer    PETSC_VIEWER_BINARY_(MPI_Comm);
210 PETSC_EXTERN PetscViewer    PETSC_VIEWER_MATLAB_(MPI_Comm);
211 PETSC_EXTERN PetscViewer   PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE;
212 
213 #define PETSC_VIEWER_STDERR_SELF  PETSC_VIEWER_STDERR_(PETSC_COMM_SELF)
214 #define PETSC_VIEWER_STDERR_WORLD PETSC_VIEWER_STDERR_(PETSC_COMM_WORLD)
215 
216 /*MC
217   PETSC_VIEWER_STDOUT_WORLD  - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD)
218 
219   Level: beginner
220 M*/
221 #define PETSC_VIEWER_STDOUT_WORLD PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD)
222 
223 /*MC
224   PETSC_VIEWER_STDOUT_SELF  - same as PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)
225 
226   Level: beginner
227 M*/
228 #define PETSC_VIEWER_STDOUT_SELF  PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)
229 
230 /*MC
231   PETSC_VIEWER_DRAW_WORLD  - same as PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD)
232 
233   Level: intermediate
234 M*/
235 #define PETSC_VIEWER_DRAW_WORLD   PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD)
236 
237 /*MC
238   PETSC_VIEWER_DRAW_SELF  - same as PETSC_VIEWER_DRAW_(PETSC_COMM_SELF)
239 
240   Level: intermediate
241 M*/
242 #define PETSC_VIEWER_DRAW_SELF    PETSC_VIEWER_DRAW_(PETSC_COMM_SELF)
243 
244 /*MC
245   PETSC_VIEWER_SOCKET_WORLD  - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD)
246 
247   Level: intermediate
248 M*/
249 #define PETSC_VIEWER_SOCKET_WORLD PETSC_VIEWER_SOCKET_(PETSC_COMM_WORLD)
250 
251 /*MC
252   PETSC_VIEWER_SOCKET_SELF  - same as PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF)
253 
254   Level: intermediate
255 M*/
256 #define PETSC_VIEWER_SOCKET_SELF  PETSC_VIEWER_SOCKET_(PETSC_COMM_SELF)
257 
258 /*MC
259   PETSC_VIEWER_BINARY_WORLD  - same as PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD)
260 
261   Level: intermediate
262 M*/
263 #define PETSC_VIEWER_BINARY_WORLD PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD)
264 
265 /*MC
266   PETSC_VIEWER_BINARY_SELF  - same as PETSC_VIEWER_BINARY_(PETSC_COMM_SELF)
267 
268   Level: intermediate
269 M*/
270 #define PETSC_VIEWER_BINARY_SELF  PETSC_VIEWER_BINARY_(PETSC_COMM_SELF)
271 
272 /*MC
273   PETSC_VIEWER_MATLAB_WORLD  - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD)
274 
275   Level: intermediate
276 M*/
277 #define PETSC_VIEWER_MATLAB_WORLD PETSC_VIEWER_MATLAB_(PETSC_COMM_WORLD)
278 
279 /*MC
280   PETSC_VIEWER_MATLAB_SELF  - same as PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF)
281 
282   Level: intermediate
283 M*/
284 #define PETSC_VIEWER_MATLAB_SELF  PETSC_VIEWER_MATLAB_(PETSC_COMM_SELF)
285 
286 #define PETSC_VIEWER_MATHEMATICA_WORLD (PetscViewerInitializeMathematicaWorld_Private(),PETSC_VIEWER_MATHEMATICA_WORLD_PRIVATE)
287 
288 #undef __FUNCT__
289 #define __FUNCT__ "PetscViewerFlowControlStart"
290 PETSC_STATIC_INLINE PetscErrorCode PetscViewerFlowControlStart(PetscViewer viewer,PetscInt *mcnt,PetscInt *cnt)
291 {
292   PetscErrorCode ierr;
293   PetscFunctionBegin;
294   ierr = PetscViewerBinaryGetFlowControl(viewer,mcnt);CHKERRQ(ierr);
295   ierr = PetscViewerBinaryGetFlowControl(viewer,cnt);CHKERRQ(ierr);
296   PetscFunctionReturn(0);
297 }
298 
299 #undef __FUNCT__
300 #define __FUNCT__ "PetscViewerFlowControlStepMaster"
301 PETSC_STATIC_INLINE PetscErrorCode PetscViewerFlowControlStepMaster(PetscViewer viewer,PetscInt i,PetscInt *mcnt,PetscInt cnt)
302 {
303   PetscErrorCode ierr;
304   MPI_Comm       comm;
305 
306   PetscFunctionBegin;
307   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
308   if (i >= *mcnt) {
309     *mcnt += cnt;
310     ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
311   }
312   PetscFunctionReturn(0);
313 }
314 
315 #undef __FUNCT__
316 #define __FUNCT__ "PetscViewerFlowControlEndMaster"
317 PETSC_STATIC_INLINE PetscErrorCode PetscViewerFlowControlEndMaster(PetscViewer viewer,PetscInt *mcnt)
318 {
319   PetscErrorCode ierr;
320   MPI_Comm       comm;
321   PetscFunctionBegin;
322   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
323   *mcnt = 0;
324   ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
325   PetscFunctionReturn(0);
326 }
327 
328 #undef __FUNCT__
329 #define __FUNCT__ "PetscViewerFlowControlStepWorker"
330 PETSC_STATIC_INLINE PetscErrorCode PetscViewerFlowControlStepWorker(PetscViewer viewer,PetscMPIInt rank,PetscInt *mcnt)
331 {
332   PetscErrorCode ierr;
333   MPI_Comm       comm;
334   PetscFunctionBegin;
335   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
336   while (PETSC_TRUE) {
337     if (rank < *mcnt) break;
338     ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
339   }
340   PetscFunctionReturn(0);
341 }
342 
343 #undef __FUNCT__
344 #define __FUNCT__ "PetscViewerFlowControlEndWorker"
345 PETSC_STATIC_INLINE PetscErrorCode PetscViewerFlowControlEndWorker(PetscViewer viewer,PetscInt *mcnt)
346 {
347   PetscErrorCode ierr;
348   MPI_Comm       comm;
349   PetscFunctionBegin;
350   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
351   while (PETSC_TRUE) {
352     ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
353     if (!*mcnt) break;
354   }
355   PetscFunctionReturn(0);
356 }
357 
358 /*
359    PetscViewer writes to MATLAB .mat file
360 */
361 PETSC_EXTERN PetscErrorCode PetscViewerMatlabPutArray(PetscViewer,int,int,const PetscScalar*,const char*);
362 PETSC_EXTERN PetscErrorCode PetscViewerMatlabGetArray(PetscViewer,int,int,PetscScalar*,const char*);
363 PETSC_EXTERN PetscErrorCode PetscViewerMatlabPutVariable(PetscViewer,const char*,void*);
364 
365 #if defined(PETSC_HAVE_AMS)
366 PETSC_EXTERN PetscErrorCode PetscObjectViewAMS(PetscObject,PetscViewer);
367 #endif
368 
369 /*S
370      PetscViewers - Abstract collection of PetscViewers. It is just an expandable array of viewers.
371 
372    Level: intermediate
373 
374   Concepts: viewing
375 
376 .seealso:  PetscViewerCreate(), PetscViewerSetType(), PetscViewerType, PetscViewer, PetscViewersCreate(),
377            PetscViewersGetViewer()
378 S*/
379 typedef struct _n_PetscViewers* PetscViewers;
380 PETSC_EXTERN PetscErrorCode PetscViewersCreate(MPI_Comm,PetscViewers*);
381 PETSC_EXTERN PetscErrorCode PetscViewersDestroy(PetscViewers*);
382 PETSC_EXTERN PetscErrorCode PetscViewersGetViewer(PetscViewers,PetscInt,PetscViewer*);
383 
384 /* Reset __FUNCT__ in case the user does not define it themselves */
385 #undef __FUNCT__
386 #define __FUNCT__ "User provided function"
387 
388 #endif
389