xref: /petsc/src/sys/classes/viewer/interface/viewreg.c (revision eb55bdffca50d68374504080e1f317d0c4a47ce0)
15c6c1daeSBarry Smith 
2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h>  /*I "petscviewer.h" I*/
3e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
4e04113cfSBarry Smith #include <petscviewersaws.h>
5bfb97211SBarry Smith #endif
65c6c1daeSBarry Smith 
7140e18c1SBarry Smith PetscFunctionList PetscViewerList = 0;
85c6c1daeSBarry Smith 
99af95d99SBarry Smith #include "../src/sys/utils/hash.h"
109af95d99SBarry Smith 
119af95d99SBarry Smith 
129de0f6ecSBarry Smith PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton = NULL;
139de0f6ecSBarry Smith KHASH_SET_INIT_STR(HTPrinted)
149de0f6ecSBarry Smith struct  _n_PetscOptionsHelpPrinted{
159de0f6ecSBarry Smith   khash_t(HTPrinted) *printed;
169de0f6ecSBarry Smith   PetscSegBuffer     strings;
179de0f6ecSBarry Smith };
189de0f6ecSBarry Smith 
199de0f6ecSBarry Smith #undef __FUNCT__
209de0f6ecSBarry Smith #define __FUNCT__ "PetscOptionsHelpPrintedDestroy"
219de0f6ecSBarry Smith PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *hp)
2294d6a431SBarry Smith {
239af95d99SBarry Smith   PetscErrorCode ierr;
249de0f6ecSBarry Smith 
259de0f6ecSBarry Smith   PetscFunctionBegin;
269de0f6ecSBarry Smith   if (!*hp) PetscFunctionReturn(0);
279de0f6ecSBarry Smith   kh_destroy(HTPrinted,(*hp)->printed);
289de0f6ecSBarry Smith   ierr = PetscSegBufferDestroy(&(*hp)->strings);CHKERRQ(ierr);
299de0f6ecSBarry Smith   ierr = PetscFree(*hp);CHKERRQ(ierr);
309de0f6ecSBarry Smith   PetscFunctionReturn(0);
319de0f6ecSBarry Smith }
329de0f6ecSBarry Smith 
339de0f6ecSBarry Smith #undef __FUNCT__
349de0f6ecSBarry Smith #define __FUNCT__ "PetscOptionsHelpPrintedCreate"
359de0f6ecSBarry Smith /*@C
369de0f6ecSBarry Smith       PetscOptionsHelpPrintedCreate - Creates an object used to manage tracking which help messages have
379de0f6ecSBarry Smith          been printed so they will not be printed again.
389de0f6ecSBarry Smith 
399de0f6ecSBarry Smith      Not collective
409de0f6ecSBarry Smith 
419de0f6ecSBarry Smith     Level: developer
429de0f6ecSBarry Smith 
439de0f6ecSBarry Smith .seealso: PetscOptionsHelpPrintedCheck(), PetscOptionsHelpPrintChecked()
449de0f6ecSBarry Smith @*/
459de0f6ecSBarry Smith PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *hp)
469de0f6ecSBarry Smith {
479de0f6ecSBarry Smith   PetscErrorCode             ierr;
489de0f6ecSBarry Smith 
499de0f6ecSBarry Smith   PetscFunctionBegin;
509de0f6ecSBarry Smith   ierr = PetscNew(hp);CHKERRQ(ierr);
519de0f6ecSBarry Smith   (*hp)->printed = kh_init(HTPrinted);
529de0f6ecSBarry Smith   ierr = PetscSegBufferCreate(sizeof(char),10000,&(*hp)->strings);CHKERRQ(ierr);
539de0f6ecSBarry Smith   PetscFunctionReturn(0);
549de0f6ecSBarry Smith }
559de0f6ecSBarry Smith 
569de0f6ecSBarry Smith #undef __FUNCT__
579de0f6ecSBarry Smith #define __FUNCT__ "PetscOptionsHelpPrintedCheck"
589de0f6ecSBarry Smith /*@C
599de0f6ecSBarry Smith       PetscOptionsHelpPrintedCheck - Checks if a particular pre, name pair has previous been entered (meaning the help message was printed)
609de0f6ecSBarry Smith 
619de0f6ecSBarry Smith      Not collective
629de0f6ecSBarry Smith 
639de0f6ecSBarry Smith     Input Parameters:
649de0f6ecSBarry Smith +     hp - the object used to manage tracking what help messages have been printed
659de0f6ecSBarry Smith .     pre - the prefix part of the string, many be NULL
669de0f6ecSBarry Smith -     name - the string to look for (cannot be NULL)
679de0f6ecSBarry Smith 
689de0f6ecSBarry Smith     Output Parameter:
699de0f6ecSBarry Smith .     found - PETSC_TRUE if the string was already set
709de0f6ecSBarry Smith 
719de0f6ecSBarry Smith     Level: intermediate
729de0f6ecSBarry Smith 
739de0f6ecSBarry Smith 
749de0f6ecSBarry Smith .seealso: PetscOptionsHelpPrintedCreate()
759de0f6ecSBarry Smith @*/
769de0f6ecSBarry Smith PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted hp,const char *pre,const char* name,PetscBool *found)
779de0f6ecSBarry Smith {
789de0f6ecSBarry Smith   size_t          l1,l2;
79c1449d8eSBarry Smith #if !defined(PETSC_HAVE_THREADSAFETY)
809de0f6ecSBarry Smith   char            *both;
819de0f6ecSBarry Smith   khint_t         newitem;
82c1449d8eSBarry Smith #endif
839de0f6ecSBarry Smith   PetscErrorCode  ierr;
849de0f6ecSBarry Smith 
859de0f6ecSBarry Smith   PetscFunctionBegin;
869de0f6ecSBarry Smith   ierr = PetscStrlen(pre,&l1);CHKERRQ(ierr);
879de0f6ecSBarry Smith   ierr = PetscStrlen(name,&l2);CHKERRQ(ierr);
889de0f6ecSBarry Smith   if (l1+l2 == 0) {
899de0f6ecSBarry Smith     *found = PETSC_FALSE;
909de0f6ecSBarry Smith     PetscFunctionReturn(0);
919de0f6ecSBarry Smith   }
92c1449d8eSBarry Smith #if !defined(PETSC_HAVE_THREADSAFETY)
939de0f6ecSBarry Smith   ierr = PetscSegBufferGet(hp->strings,l1+l2+1,&both);CHKERRQ(ierr);
949de0f6ecSBarry Smith   ierr = PetscStrcpy(both,pre);CHKERRQ(ierr);
959de0f6ecSBarry Smith   ierr = PetscStrcat(both,name);CHKERRQ(ierr);
969de0f6ecSBarry Smith   kh_put(HTPrinted,hp->printed,both,&newitem);
979de0f6ecSBarry Smith   if (!newitem) {
989de0f6ecSBarry Smith     ierr = PetscSegBufferUnuse(hp->strings,l1+l2+1);CHKERRQ(ierr);
999de0f6ecSBarry Smith   }
1009de0f6ecSBarry Smith   *found = newitem ? PETSC_FALSE : PETSC_TRUE;
101c1449d8eSBarry Smith #else
102c1449d8eSBarry Smith   *found = PETSC_FALSE;
103c1449d8eSBarry Smith #endif
1049de0f6ecSBarry Smith   PetscFunctionReturn(0);
10594d6a431SBarry Smith }
10694d6a431SBarry Smith 
107*eb55bdffSLawrence Mitchell static PetscBool noviewer = PETSC_FALSE;
108*eb55bdffSLawrence Mitchell static PetscBool noviewers[PETSCVIEWERGETVIEWEROFFPUSHESMAX];
109*eb55bdffSLawrence Mitchell static PetscInt  inoviewers = 0;
110*eb55bdffSLawrence Mitchell 
111*eb55bdffSLawrence Mitchell #undef __FUNCT__
112*eb55bdffSLawrence Mitchell #define __FUNCT__ "PetscOptionsPushGetViewerOff"
113*eb55bdffSLawrence Mitchell /*@
114*eb55bdffSLawrence Mitchell   PetscOptionsPushGetViewerOff - control whether PetscOptionsGetViewer returns a viewer.
115*eb55bdffSLawrence Mitchell 
116*eb55bdffSLawrence Mitchell   Logically Collective
117*eb55bdffSLawrence Mitchell 
118*eb55bdffSLawrence Mitchell   Input Parameter:
119*eb55bdffSLawrence Mitchell . flg - PETSC_TRUE to turn off viewer creation, PETSC_FALSE to turn it on.
120*eb55bdffSLawrence Mitchell 
121*eb55bdffSLawrence Mitchell   Level: developer
122*eb55bdffSLawrence Mitchell 
123*eb55bdffSLawrence Mitchell   Notes: Calling XXXViewFromOptions in an inner loop can be very expensive.  This can appear, for example, when using
124*eb55bdffSLawrence Mitchell    many small subsolves.  Call this function to control viewer creation in PetscOptionsGetViewer, thus removing the expensive XXXViewFromOptions calls.
125*eb55bdffSLawrence Mitchell 
126*eb55bdffSLawrence Mitchell .seealso: PetscOptionsGetViewer(), PetscOptionsPopGetViewerOff()
127*eb55bdffSLawrence Mitchell @*/
128*eb55bdffSLawrence Mitchell PetscErrorCode  PetscOptionsPushGetViewerOff(PetscBool flg)
129*eb55bdffSLawrence Mitchell {
130*eb55bdffSLawrence Mitchell   PetscFunctionBegin;
131*eb55bdffSLawrence Mitchell   if (inoviewers > PETSCVIEWERGETVIEWEROFFPUSHESMAX - 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many PetscOptionsPushGetViewerOff(), perhaps you forgot PetscOptionsPopGetViewerOff()?");
132*eb55bdffSLawrence Mitchell 
133*eb55bdffSLawrence Mitchell   noviewers[inoviewers++] = noviewer;
134*eb55bdffSLawrence Mitchell   noviewer = flg;
135*eb55bdffSLawrence Mitchell   PetscFunctionReturn(0);
136*eb55bdffSLawrence Mitchell }
137*eb55bdffSLawrence Mitchell 
138*eb55bdffSLawrence Mitchell #undef __FUNCT__
139*eb55bdffSLawrence Mitchell #define __FUNCT__ "PetscOptionsPopGetViewerOff"
140*eb55bdffSLawrence Mitchell /*@
141*eb55bdffSLawrence Mitchell   PetscOptionsPopGetViewerOff - reset whether PetscOptionsGetViewer returns a viewer.
142*eb55bdffSLawrence Mitchell 
143*eb55bdffSLawrence Mitchell   Logically Collective
144*eb55bdffSLawrence Mitchell 
145*eb55bdffSLawrence Mitchell   Level: developer
146*eb55bdffSLawrence Mitchell 
147*eb55bdffSLawrence Mitchell   Notes: Calling XXXViewFromOptions in an inner loop can be very expensive.  This can appear, for example, when using
148*eb55bdffSLawrence Mitchell    many small subsolves.  Call this function to control viewer creation in PetscOptionsGetViewer, thus removing the expensive XXXViewFromOptions calls.
149*eb55bdffSLawrence Mitchell 
150*eb55bdffSLawrence Mitchell .seealso: PetscOptionsGetViewer(), PetscOptionsPushGetViewerOff()
151*eb55bdffSLawrence Mitchell @*/
152*eb55bdffSLawrence Mitchell PetscErrorCode  PetscOptionsPopGetViewerOff()
153*eb55bdffSLawrence Mitchell {
154*eb55bdffSLawrence Mitchell   PetscFunctionBegin;
155*eb55bdffSLawrence Mitchell   if (!inoviewers) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many PetscOptionsPopGetViewerOff(), perhaps you forgot PetscOptionsPushGetViewerOff()?");
156*eb55bdffSLawrence Mitchell   noviewer = noviewers[--inoviewers];
157*eb55bdffSLawrence Mitchell   PetscFunctionReturn(0);
158*eb55bdffSLawrence Mitchell }
159*eb55bdffSLawrence Mitchell 
160*eb55bdffSLawrence Mitchell #undef __FUNCT__
161*eb55bdffSLawrence Mitchell #define __FUNCT__ "PetscOptionsGetViewerOff"
162*eb55bdffSLawrence Mitchell /*@
163*eb55bdffSLawrence Mitchell   PetscOptionsGetViewerOff - does PetscOptionsGetViewer return a viewer?
164*eb55bdffSLawrence Mitchell 
165*eb55bdffSLawrence Mitchell   Logically Collective
166*eb55bdffSLawrence Mitchell 
167*eb55bdffSLawrence Mitchell   Output Parameter:
168*eb55bdffSLawrence Mitchell . flg - whether viewers are returned.
169*eb55bdffSLawrence Mitchell 
170*eb55bdffSLawrence Mitchell   Level: developer
171*eb55bdffSLawrence Mitchell 
172*eb55bdffSLawrence Mitchell   Notes: Calling XXXViewFromOptions in an inner loop can be very expensive.  This can appear, for example, when using
173*eb55bdffSLawrence Mitchell    many small subsolves.
174*eb55bdffSLawrence Mitchell 
175*eb55bdffSLawrence Mitchell .seealso: PetscOptionsGetViewer(), PetscOptionsPushGetViewerOff(), PetscOptionsPopGetViewerOff()
176*eb55bdffSLawrence Mitchell @*/
177*eb55bdffSLawrence Mitchell PetscErrorCode  PetscOptionsGetViewerOff(PetscBool *flg)
178*eb55bdffSLawrence Mitchell {
179*eb55bdffSLawrence Mitchell   PetscFunctionBegin;
180*eb55bdffSLawrence Mitchell   PetscValidPointer(flg,0);
181*eb55bdffSLawrence Mitchell   *flg = noviewer;
182*eb55bdffSLawrence Mitchell   PetscFunctionReturn(0);
183*eb55bdffSLawrence Mitchell }
184*eb55bdffSLawrence Mitchell 
1852bf49c77SBarry Smith #undef __FUNCT__
1862bf49c77SBarry Smith #define __FUNCT__ "PetscOptionsGetViewer"
1872bf49c77SBarry Smith /*@C
1882bf49c77SBarry Smith    PetscOptionsGetViewer - Gets a viewer appropriate for the type indicated by the user
1892bf49c77SBarry Smith 
1902bf49c77SBarry Smith    Collective on MPI_Comm
1912bf49c77SBarry Smith 
1922bf49c77SBarry Smith    Input Parameters:
1932bf49c77SBarry Smith +  comm - the communicator to own the viewer
1940298fd71SBarry Smith .  pre - the string to prepend to the name or NULL
1952bf49c77SBarry Smith -  name - the option one is seeking
1962bf49c77SBarry Smith 
1972bf49c77SBarry Smith    Output Parameter:
198bb1d7374SBarry Smith +  viewer - the viewer, pass NULL if not needed
199bb1d7374SBarry Smith .  format - the PetscViewerFormat requested by the user, pass NULL if not needed
2002bf49c77SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
2012bf49c77SBarry Smith 
2022bf49c77SBarry Smith    Level: intermediate
2032bf49c77SBarry Smith 
2042bf49c77SBarry Smith    Notes: If no value is provided ascii:stdout is used
205d1da0b69SBarry Smith $       ascii[:[filename][:[format][:append]]]    defaults to stdout - format can be one of ascii_info, ascii_info_detail, or ascii_matlab,
206d1da0b69SBarry Smith                                                   for example ascii::ascii_info prints just the information about the object not all details
207d1da0b69SBarry Smith                                                   unless :append is given filename opens in write mode, overwriting what was already there
208d1da0b69SBarry Smith $       binary[:[filename][:[format][:append]]]   defaults to the file binaryoutput
209acd7d2deSBarry Smith $       draw[:drawtype[:filename]]                for example, draw:tikz, draw:tikz:figure.tex  or draw:x
2102bf49c77SBarry Smith $       socket[:port]                             defaults to the standard output port
2112a359c20SBarry Smith $       saws[:communicatorname]                    publishes object to the Scientific Application Webserver (SAWs)
2122bf49c77SBarry Smith 
213cffb1e40SBarry Smith    Use PetscViewerDestroy() after using the viewer, otherwise a memory leak will occur
2142bf49c77SBarry Smith 
215*eb55bdffSLawrence Mitchell    You can control whether calls to this function create a viewer (or return early with *set of PETSC_FALSE) with
216*eb55bdffSLawrence Mitchell    PetscOptionsPushGetViewerOff.  This is useful if calling many small subsolves, in which case XXXViewFromOptions can take
217*eb55bdffSLawrence Mitchell    an appreciable fraction of the runtime.
218*eb55bdffSLawrence Mitchell 
21927b0f280SBarry Smith    If PETSc is configured with --with-viewfromoptions=0 this function always returns with *set of PETSC_FALSE
22027b0f280SBarry Smith 
2212bf49c77SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(),
2222bf49c77SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
2232bf49c77SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
2242bf49c77SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
2252bf49c77SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
2262bf49c77SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
227*eb55bdffSLawrence Mitchell           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsPushGetViewerOff(), PetscOptionsPopGetViewerOff(),
228*eb55bdffSLawrence Mitchell           PetscOptionsGetViewerOff()
2292bf49c77SBarry Smith @*/
230cffb1e40SBarry Smith PetscErrorCode  PetscOptionsGetViewer(MPI_Comm comm,const char pre[],const char name[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
2312bf49c77SBarry Smith {
2322bf49c77SBarry Smith   char                           *value;
2332bf49c77SBarry Smith   PetscErrorCode                 ierr;
23420610d12SBarry Smith   PetscBool                      flag,hashelp;
2352bf49c77SBarry Smith 
2362bf49c77SBarry Smith   PetscFunctionBegin;
2372bf49c77SBarry Smith   PetscValidCharPointer(name,3);
2382bf49c77SBarry Smith 
23927b0f280SBarry Smith   if (set) *set = PETSC_FALSE;
24027b0f280SBarry Smith #if defined(PETSC_SKIP_VIEWFROMOPTIONS)
24127b0f280SBarry Smith   PetscFunctionReturn(0);
24227b0f280SBarry Smith #endif
243*eb55bdffSLawrence Mitchell   ierr = PetscOptionsGetViewerOff(&flag);CHKERRQ(ierr);
244*eb55bdffSLawrence Mitchell   if (flag) PetscFunctionReturn(0);
24527b0f280SBarry Smith 
246c5929fdfSBarry Smith   ierr = PetscOptionsHasName(NULL,NULL,"-help",&hashelp);CHKERRQ(ierr);
24720610d12SBarry Smith   if (hashelp) {
2489de0f6ecSBarry Smith     PetscBool found;
2499af95d99SBarry Smith 
2509de0f6ecSBarry Smith     if (!PetscOptionsHelpPrintedSingleton) {
2519de0f6ecSBarry Smith       ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr);
2529af95d99SBarry Smith     }
2539de0f6ecSBarry Smith     ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,pre,name,&found);CHKERRQ(ierr);
2549de0f6ecSBarry Smith     if (!found) {
25594d6a431SBarry Smith       if (viewer) {
25694d6a431SBarry Smith         ierr = (*PetscHelpPrintf)(comm,"\n  -%s%s ascii[:[filename][:[format][:append]]]: %s (%s)\n",pre ? pre : "",name+1,"Prints object to stdout or ASCII file","PetscOptionsGetViewer");CHKERRQ(ierr);
25794d6a431SBarry Smith         ierr = (*PetscHelpPrintf)(comm,"    -%s%s binary[:[filename][:[format][:append]]]: %s (%s)\n",pre ? pre : "",name+1,"Saves object to a binary file","PetscOptionsGetViewer");CHKERRQ(ierr);
258acd7d2deSBarry Smith         ierr = (*PetscHelpPrintf)(comm,"    -%s%s draw[:drawtype[:filename]] %s (%s)\n",pre ? pre : "",name+1,"Draws object","PetscOptionsGetViewer");CHKERRQ(ierr);
25994d6a431SBarry Smith         ierr = (*PetscHelpPrintf)(comm,"    -%s%s socket[:port]: %s (%s)\n",pre ? pre : "",name+1,"Pushes object to a Unix socket","PetscOptionsGetViewer");CHKERRQ(ierr);
26094d6a431SBarry Smith         ierr = (*PetscHelpPrintf)(comm,"    -%s%s saws[:communicatorname]: %s (%s)\n\n",pre ? pre : "",name+1,"Publishes object to SAWs","PetscOptionsGetViewer");CHKERRQ(ierr);
26194d6a431SBarry Smith       } else {
26294d6a431SBarry Smith         ierr = (*PetscHelpPrintf)(comm,"    -%s%s\n",pre ? pre : "",name+1);CHKERRQ(ierr);
26394d6a431SBarry Smith       }
26494d6a431SBarry Smith     }
26520610d12SBarry Smith   }
266685405a1SBarry Smith 
267e3f3e4b6SBarry Smith   if (format) *format = PETSC_VIEWER_DEFAULT;
268c5929fdfSBarry Smith   ierr = PetscOptionsFindPair_Private(NULL,pre,name,&value,&flag);CHKERRQ(ierr);
2692bf49c77SBarry Smith   if (flag) {
2702bf49c77SBarry Smith     if (set) *set = PETSC_TRUE;
2712bf49c77SBarry Smith     if (!value) {
272bb1d7374SBarry Smith       if (viewer) {
2732bf49c77SBarry Smith         ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
274706a11cbSBarry Smith         ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
275bb1d7374SBarry Smith       }
2762bf49c77SBarry Smith     } else {
27735d27ee3SJed Brown       char       *loc0_vtype,*loc1_fname,*loc2_fmt = NULL,*loc3_fmode = NULL;
2782bf49c77SBarry Smith       PetscInt   cnt;
279a75e6a4aSMatthew G. Knepley       const char *viewers[] = {PETSCVIEWERASCII,PETSCVIEWERBINARY,PETSCVIEWERDRAW,PETSCVIEWERSOCKET,PETSCVIEWERMATLAB,PETSCVIEWERSAWS,PETSCVIEWERVTK,PETSCVIEWERHDF5,0};
2802bf49c77SBarry Smith 
28135d27ee3SJed Brown       ierr = PetscStrallocpy(value,&loc0_vtype);CHKERRQ(ierr);
28235d27ee3SJed Brown       ierr = PetscStrchr(loc0_vtype,':',&loc1_fname);CHKERRQ(ierr);
28335d27ee3SJed Brown       if (loc1_fname) {
28435d27ee3SJed Brown         *loc1_fname++ = 0;
28535d27ee3SJed Brown         ierr = PetscStrchr(loc1_fname,':',&loc2_fmt);CHKERRQ(ierr);
28635d27ee3SJed Brown       }
28735d27ee3SJed Brown       if (loc2_fmt) {
28835d27ee3SJed Brown         *loc2_fmt++ = 0;
28935d27ee3SJed Brown         ierr = PetscStrchr(loc2_fmt,':',&loc3_fmode);CHKERRQ(ierr);
29035d27ee3SJed Brown       }
29135d27ee3SJed Brown       if (loc3_fmode) *loc3_fmode++ = 0;
29235d27ee3SJed Brown       ierr = PetscStrendswithwhich(*loc0_vtype ? loc0_vtype : "ascii",viewers,&cnt);CHKERRQ(ierr);
29335d27ee3SJed Brown       if (cnt > (PetscInt) sizeof(viewers)-1) SETERRQ1(comm,PETSC_ERR_ARG_OUTOFRANGE,"Unknown viewer type: %s",loc0_vtype);
294bb1d7374SBarry Smith       if (viewer) {
29535d27ee3SJed Brown         if (!loc1_fname) {
29643b63833SBarry Smith           switch (cnt) {
29743b63833SBarry Smith           case 0:
2982bf49c77SBarry Smith             ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
29943b63833SBarry Smith             break;
30043b63833SBarry Smith           case 1:
301aa1c909bSJed Brown             if (!(*viewer = PETSC_VIEWER_BINARY_(comm))) CHKERRQ(PETSC_ERR_PLIB);
30243b63833SBarry Smith             break;
30343b63833SBarry Smith           case 2:
304aa1c909bSJed Brown             if (!(*viewer = PETSC_VIEWER_DRAW_(comm))) CHKERRQ(PETSC_ERR_PLIB);
30543b63833SBarry Smith             break;
306b58ca069SBarry Smith #if defined(PETSC_USE_SOCKET_VIEWER)
30743b63833SBarry Smith           case 3:
308aa1c909bSJed Brown             if (!(*viewer = PETSC_VIEWER_SOCKET_(comm))) CHKERRQ(PETSC_ERR_PLIB);
30943b63833SBarry Smith             break;
310b58ca069SBarry Smith #endif
31143b63833SBarry Smith #if defined(PETSC_HAVE_MATLAB_ENGINE)
31243b63833SBarry Smith           case 4:
313aa1c909bSJed Brown             if (!(*viewer = PETSC_VIEWER_MATLAB_(comm))) CHKERRQ(PETSC_ERR_PLIB);
31443b63833SBarry Smith             break;
31543b63833SBarry Smith #endif
316e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
317bfb97211SBarry Smith           case 5:
318e04113cfSBarry Smith             if (!(*viewer = PETSC_VIEWER_SAWS_(comm))) CHKERRQ(PETSC_ERR_PLIB);
319bfb97211SBarry Smith             break;
320bfb97211SBarry Smith #endif
321a75e6a4aSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5)
322a75e6a4aSMatthew G. Knepley           case 7:
323a75e6a4aSMatthew G. Knepley             if (!(*viewer = PETSC_VIEWER_HDF5_(comm))) CHKERRQ(PETSC_ERR_PLIB);
324a75e6a4aSMatthew G. Knepley             break;
325a75e6a4aSMatthew G. Knepley #endif
326aa1c909bSJed Brown           default: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported viewer %s",loc0_vtype);
3277f677774SBarry Smith           }
328706a11cbSBarry Smith           ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
3297f677774SBarry Smith         } else {
33035d27ee3SJed Brown           if (loc2_fmt && !*loc1_fname && (cnt == 0)) { /* ASCII format without file name */
3317f677774SBarry Smith             ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
332706a11cbSBarry Smith             ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
3337f677774SBarry Smith           } else {
3343550efbcSJed Brown             PetscFileMode fmode;
3352bf49c77SBarry Smith             ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
33635d27ee3SJed Brown             ierr = PetscViewerSetType(*viewer,*loc0_vtype ? loc0_vtype : "ascii");CHKERRQ(ierr);
3373550efbcSJed Brown             fmode = FILE_MODE_WRITE;
3383550efbcSJed Brown             if (loc3_fmode && *loc3_fmode) { /* Has non-empty file mode ("write" or "append") */
33935d27ee3SJed Brown               ierr = PetscEnumFind(PetscFileModes,loc3_fmode,(PetscEnum*)&fmode,&flag);CHKERRQ(ierr);
3403550efbcSJed Brown               if (!flag) SETERRQ1(comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown file mode: %s",loc3_fmode);
3417f677774SBarry Smith             }
342acd7d2deSBarry Smith             if (loc2_fmt) {
343acd7d2deSBarry Smith               PetscBool tk;
344acd7d2deSBarry Smith               ierr = PetscStrcmp(loc1_fname,"tikz",&tk);CHKERRQ(ierr);
345acd7d2deSBarry Smith               if (tk) {
346acd7d2deSBarry Smith                 ierr = PetscViewerDrawSetInfo(*viewer,NULL,loc2_fmt,0,0,0,0);CHKERRQ(ierr);
347acd7d2deSBarry Smith                 *loc2_fmt = 0;
348acd7d2deSBarry Smith               }
349acd7d2deSBarry Smith             }
3503550efbcSJed Brown             ierr = PetscViewerFileSetMode(*viewer,flag?fmode:FILE_MODE_WRITE);CHKERRQ(ierr);
35135d27ee3SJed Brown             ierr = PetscViewerFileSetName(*viewer,loc1_fname);CHKERRQ(ierr);
352d1da0b69SBarry Smith             ierr = PetscViewerDrawSetDrawType(*viewer,loc1_fname);CHKERRQ(ierr);
35305315717SToby Isaac           }
35405315717SToby Isaac         }
355bb1d7374SBarry Smith       }
356bb1d7374SBarry Smith       if (viewer) {
357bb1d7374SBarry Smith         ierr = PetscViewerSetUp(*viewer);CHKERRQ(ierr);
358bb1d7374SBarry Smith       }
35935d27ee3SJed Brown       if (loc2_fmt && *loc2_fmt) {
36035d27ee3SJed Brown         ierr = PetscEnumFind(PetscViewerFormats,loc2_fmt,(PetscEnum*)format,&flag);CHKERRQ(ierr);
36135d27ee3SJed Brown         if (!flag) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unknown viewer format %s",loc2_fmt);CHKERRQ(ierr);
3627f677774SBarry Smith       }
36335d27ee3SJed Brown       ierr = PetscFree(loc0_vtype);CHKERRQ(ierr);
3642bf49c77SBarry Smith     }
3652bf49c77SBarry Smith   }
3662bf49c77SBarry Smith   PetscFunctionReturn(0);
3672bf49c77SBarry Smith }
3682bf49c77SBarry Smith 
3692bf49c77SBarry Smith #undef __FUNCT__
3705c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate"
3715c6c1daeSBarry Smith /*@
3725c6c1daeSBarry Smith    PetscViewerCreate - Creates a viewing context
3735c6c1daeSBarry Smith 
3745c6c1daeSBarry Smith    Collective on MPI_Comm
3755c6c1daeSBarry Smith 
3765c6c1daeSBarry Smith    Input Parameter:
3775c6c1daeSBarry Smith .  comm - MPI communicator
3785c6c1daeSBarry Smith 
3795c6c1daeSBarry Smith    Output Parameter:
3805c6c1daeSBarry Smith .  inviewer - location to put the PetscViewer context
3815c6c1daeSBarry Smith 
3825c6c1daeSBarry Smith    Level: advanced
3835c6c1daeSBarry Smith 
3845c6c1daeSBarry Smith    Concepts: graphics^creating PetscViewer
3855c6c1daeSBarry Smith    Concepts: file input/output^creating PetscViewer
3865c6c1daeSBarry Smith    Concepts: sockets^creating PetscViewer
3875c6c1daeSBarry Smith 
3885c6c1daeSBarry Smith .seealso: PetscViewerDestroy(), PetscViewerSetType(), PetscViewerType
3895c6c1daeSBarry Smith 
3905c6c1daeSBarry Smith @*/
3915c6c1daeSBarry Smith PetscErrorCode  PetscViewerCreate(MPI_Comm comm,PetscViewer *inviewer)
3925c6c1daeSBarry Smith {
3935c6c1daeSBarry Smith   PetscViewer    viewer;
3945c6c1daeSBarry Smith   PetscErrorCode ierr;
3955c6c1daeSBarry Smith 
3965c6c1daeSBarry Smith   PetscFunctionBegin;
3975c6c1daeSBarry Smith   *inviewer = 0;
398607a6623SBarry Smith   ierr = PetscViewerInitializePackage();CHKERRQ(ierr);
39973107ff1SLisandro Dalcin   ierr         = PetscHeaderCreate(viewer,PETSC_VIEWER_CLASSID,"PetscViewer","PetscViewer","Viewer",comm,PetscViewerDestroy,NULL);CHKERRQ(ierr);
4005c6c1daeSBarry Smith   *inviewer    = viewer;
4015c6c1daeSBarry Smith   viewer->data = 0;
4025c6c1daeSBarry Smith   PetscFunctionReturn(0);
4035c6c1daeSBarry Smith }
4045c6c1daeSBarry Smith 
4055c6c1daeSBarry Smith #undef __FUNCT__
4065c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetType"
4075c6c1daeSBarry Smith /*@C
4085c6c1daeSBarry Smith    PetscViewerSetType - Builds PetscViewer for a particular implementation.
4095c6c1daeSBarry Smith 
4105c6c1daeSBarry Smith    Collective on PetscViewer
4115c6c1daeSBarry Smith 
4125c6c1daeSBarry Smith    Input Parameter:
4135c6c1daeSBarry Smith +  viewer      - the PetscViewer context
4148f6c3df8SBarry Smith -  type        - for example, PETSCVIEWERASCII
4155c6c1daeSBarry Smith 
4165c6c1daeSBarry Smith    Options Database Command:
4175c6c1daeSBarry Smith .  -draw_type  <type> - Sets the type; use -help for a list
4185c6c1daeSBarry Smith     of available methods (for instance, ascii)
4195c6c1daeSBarry Smith 
4205c6c1daeSBarry Smith    Level: advanced
4215c6c1daeSBarry Smith 
4225c6c1daeSBarry Smith    Notes:
4235c6c1daeSBarry Smith    See "include/petscviewer.h" for available methods (for instance,
4248f6c3df8SBarry Smith    PETSCVIEWERSOCKET)
4255c6c1daeSBarry Smith 
4266a9046bcSBarry Smith .seealso: PetscViewerCreate(), PetscViewerGetType(), PetscViewerType, PetscViewerPushFormat()
4275c6c1daeSBarry Smith @*/
4285c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetType(PetscViewer viewer,PetscViewerType type)
4295c6c1daeSBarry Smith {
4305c6c1daeSBarry Smith   PetscErrorCode ierr,(*r)(PetscViewer);
4315c6c1daeSBarry Smith   PetscBool      match;
4325c6c1daeSBarry Smith 
4335c6c1daeSBarry Smith   PetscFunctionBegin;
4345c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
4355c6c1daeSBarry Smith   PetscValidCharPointer(type,2);
4365c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,type,&match);CHKERRQ(ierr);
4375c6c1daeSBarry Smith   if (match) PetscFunctionReturn(0);
4385c6c1daeSBarry Smith 
4395c6c1daeSBarry Smith   /* cleanup any old type that may be there */
4405c6c1daeSBarry Smith   if (viewer->data) {
4415c6c1daeSBarry Smith     ierr         = (*viewer->ops->destroy)(viewer);CHKERRQ(ierr);
442a297a907SKarl Rupp 
4430298fd71SBarry Smith     viewer->ops->destroy = NULL;
4445c6c1daeSBarry Smith     viewer->data         = 0;
4455c6c1daeSBarry Smith   }
4465c6c1daeSBarry Smith   ierr = PetscMemzero(viewer->ops,sizeof(struct _PetscViewerOps));CHKERRQ(ierr);
4475c6c1daeSBarry Smith 
4481c9cd337SJed Brown   ierr =  PetscFunctionListFind(PetscViewerList,type,&r);CHKERRQ(ierr);
4495c6c1daeSBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscViewer type given: %s",type);
4505c6c1daeSBarry Smith 
4515c6c1daeSBarry Smith   ierr = PetscObjectChangeTypeName((PetscObject)viewer,type);CHKERRQ(ierr);
4525c6c1daeSBarry Smith   ierr = (*r)(viewer);CHKERRQ(ierr);
4535c6c1daeSBarry Smith   PetscFunctionReturn(0);
4545c6c1daeSBarry Smith }
4555c6c1daeSBarry Smith 
4565c6c1daeSBarry Smith #undef __FUNCT__
4575c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerRegister"
4581c84c290SBarry Smith /*@C
4591c84c290SBarry Smith    PetscViewerRegister - Adds a viewer
4601c84c290SBarry Smith 
4611c84c290SBarry Smith    Not Collective
4621c84c290SBarry Smith 
4631c84c290SBarry Smith    Input Parameters:
4641c84c290SBarry Smith +  name_solver - name of a new user-defined viewer
4651c84c290SBarry Smith -  routine_create - routine to create method context
4661c84c290SBarry Smith 
4671c84c290SBarry Smith    Level: developer
4681c84c290SBarry Smith    Notes:
4691c84c290SBarry Smith    PetscViewerRegister() may be called multiple times to add several user-defined viewers.
4701c84c290SBarry Smith 
4711c84c290SBarry Smith    Sample usage:
4721c84c290SBarry Smith .vb
473bdf89e91SBarry Smith    PetscViewerRegister("my_viewer_type",MyViewerCreate);
4741c84c290SBarry Smith .ve
4751c84c290SBarry Smith 
4761c84c290SBarry Smith    Then, your solver can be chosen with the procedural interface via
4771c84c290SBarry Smith $     PetscViewerSetType(viewer,"my_viewer_type")
4781c84c290SBarry Smith    or at runtime via the option
4791c84c290SBarry Smith $     -viewer_type my_viewer_type
4801c84c290SBarry Smith 
4811c84c290SBarry Smith   Concepts: registering^Viewers
4821c84c290SBarry Smith 
4831c84c290SBarry Smith .seealso: PetscViewerRegisterAll(), PetscViewerRegisterDestroy()
4841c84c290SBarry Smith  @*/
485bdf89e91SBarry Smith PetscErrorCode  PetscViewerRegister(const char *sname,PetscErrorCode (*function)(PetscViewer))
4865c6c1daeSBarry Smith {
4875c6c1daeSBarry Smith   PetscErrorCode ierr;
4885c6c1daeSBarry Smith 
4895c6c1daeSBarry Smith   PetscFunctionBegin;
490a240a19fSJed Brown   ierr = PetscFunctionListAdd(&PetscViewerList,sname,function);CHKERRQ(ierr);
4915c6c1daeSBarry Smith   PetscFunctionReturn(0);
4925c6c1daeSBarry Smith }
4935c6c1daeSBarry Smith 
4945c6c1daeSBarry Smith #undef __FUNCT__
4955c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetFromOptions"
4965c6c1daeSBarry Smith /*@C
4975c6c1daeSBarry Smith    PetscViewerSetFromOptions - Sets the graphics type from the options database.
4985c6c1daeSBarry Smith       Defaults to a PETSc X windows graphics.
4995c6c1daeSBarry Smith 
5005c6c1daeSBarry Smith    Collective on PetscViewer
5015c6c1daeSBarry Smith 
5025c6c1daeSBarry Smith    Input Parameter:
5035c6c1daeSBarry Smith .     PetscViewer - the graphics context
5045c6c1daeSBarry Smith 
5055c6c1daeSBarry Smith    Level: intermediate
5065c6c1daeSBarry Smith 
5075c6c1daeSBarry Smith    Notes:
5085c6c1daeSBarry Smith     Must be called after PetscViewerCreate() before the PetscViewer is used.
5095c6c1daeSBarry Smith 
5105c6c1daeSBarry Smith   Concepts: PetscViewer^setting options
5115c6c1daeSBarry Smith 
5125c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType
5135c6c1daeSBarry Smith 
5145c6c1daeSBarry Smith @*/
5155c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetFromOptions(PetscViewer viewer)
5165c6c1daeSBarry Smith {
5175c6c1daeSBarry Smith   PetscErrorCode    ierr;
5185c6c1daeSBarry Smith   char              vtype[256];
5195c6c1daeSBarry Smith   PetscBool         flg;
5205c6c1daeSBarry Smith 
5215c6c1daeSBarry Smith   PetscFunctionBegin;
5225c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
5235c6c1daeSBarry Smith 
5245c6c1daeSBarry Smith   if (!PetscViewerList) {
525607a6623SBarry Smith     ierr = PetscViewerRegisterAll();CHKERRQ(ierr);
5265c6c1daeSBarry Smith   }
5275c6c1daeSBarry Smith   ierr = PetscObjectOptionsBegin((PetscObject)viewer);CHKERRQ(ierr);
528a264d7a6SBarry Smith   ierr = PetscOptionsFList("-viewer_type","Type of PetscViewer","None",PetscViewerList,(char*)(((PetscObject)viewer)->type_name ? ((PetscObject)viewer)->type_name : PETSCVIEWERASCII),vtype,256,&flg);CHKERRQ(ierr);
5295c6c1daeSBarry Smith   if (flg) {
5305c6c1daeSBarry Smith     ierr = PetscViewerSetType(viewer,vtype);CHKERRQ(ierr);
5315c6c1daeSBarry Smith   }
5325c6c1daeSBarry Smith   /* type has not been set? */
5335c6c1daeSBarry Smith   if (!((PetscObject)viewer)->type_name) {
5345c6c1daeSBarry Smith     ierr = PetscViewerSetType(viewer,PETSCVIEWERASCII);CHKERRQ(ierr);
5355c6c1daeSBarry Smith   }
5365c6c1daeSBarry Smith   if (viewer->ops->setfromoptions) {
537e55864a3SBarry Smith     ierr = (*viewer->ops->setfromoptions)(PetscOptionsObject,viewer);CHKERRQ(ierr);
5385c6c1daeSBarry Smith   }
5395c6c1daeSBarry Smith 
5405c6c1daeSBarry Smith   /* process any options handlers added with PetscObjectAddOptionsHandler() */
5410633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject)viewer);CHKERRQ(ierr);
542ce1779c8SBarry Smith   ierr = PetscViewerViewFromOptions(viewer,NULL,"-viewer_view");CHKERRQ(ierr);
5435c6c1daeSBarry Smith   ierr = PetscOptionsEnd();CHKERRQ(ierr);
5445c6c1daeSBarry Smith   PetscFunctionReturn(0);
5455c6c1daeSBarry Smith }
546816f7b76SBarry Smith 
547816f7b76SBarry Smith #undef __FUNCT__
548816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlStart"
549816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlStart(PetscViewer viewer,PetscInt *mcnt,PetscInt *cnt)
550816f7b76SBarry Smith {
551816f7b76SBarry Smith   PetscErrorCode ierr;
552816f7b76SBarry Smith   PetscFunctionBegin;
553816f7b76SBarry Smith   ierr = PetscViewerBinaryGetFlowControl(viewer,mcnt);CHKERRQ(ierr);
554816f7b76SBarry Smith   ierr = PetscViewerBinaryGetFlowControl(viewer,cnt);CHKERRQ(ierr);
555816f7b76SBarry Smith   PetscFunctionReturn(0);
556816f7b76SBarry Smith }
557816f7b76SBarry Smith 
558816f7b76SBarry Smith #undef __FUNCT__
559816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlStepMaster"
560816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlStepMaster(PetscViewer viewer,PetscInt i,PetscInt *mcnt,PetscInt cnt)
561816f7b76SBarry Smith {
562816f7b76SBarry Smith   PetscErrorCode ierr;
563816f7b76SBarry Smith   MPI_Comm       comm;
564816f7b76SBarry Smith 
565816f7b76SBarry Smith   PetscFunctionBegin;
566816f7b76SBarry Smith   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
567816f7b76SBarry Smith   if (i >= *mcnt) {
568816f7b76SBarry Smith     *mcnt += cnt;
569816f7b76SBarry Smith     ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
570816f7b76SBarry Smith   }
571816f7b76SBarry Smith   PetscFunctionReturn(0);
572816f7b76SBarry Smith }
573816f7b76SBarry Smith 
574816f7b76SBarry Smith #undef __FUNCT__
575816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlEndMaster"
576816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlEndMaster(PetscViewer viewer,PetscInt *mcnt)
577816f7b76SBarry Smith {
578816f7b76SBarry Smith   PetscErrorCode ierr;
579816f7b76SBarry Smith   MPI_Comm       comm;
580816f7b76SBarry Smith   PetscFunctionBegin;
581816f7b76SBarry Smith   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
582816f7b76SBarry Smith   *mcnt = 0;
583816f7b76SBarry Smith   ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
584816f7b76SBarry Smith   PetscFunctionReturn(0);
585816f7b76SBarry Smith }
586816f7b76SBarry Smith 
587816f7b76SBarry Smith #undef __FUNCT__
588816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlStepWorker"
589816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlStepWorker(PetscViewer viewer,PetscMPIInt rank,PetscInt *mcnt)
590816f7b76SBarry Smith {
591816f7b76SBarry Smith   PetscErrorCode ierr;
592816f7b76SBarry Smith   MPI_Comm       comm;
593816f7b76SBarry Smith   PetscFunctionBegin;
594816f7b76SBarry Smith   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
595816f7b76SBarry Smith   while (PETSC_TRUE) {
596816f7b76SBarry Smith     if (rank < *mcnt) break;
597816f7b76SBarry Smith     ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
598816f7b76SBarry Smith   }
599816f7b76SBarry Smith   PetscFunctionReturn(0);
600816f7b76SBarry Smith }
601816f7b76SBarry Smith 
602816f7b76SBarry Smith #undef __FUNCT__
603816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlEndWorker"
604816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlEndWorker(PetscViewer viewer,PetscInt *mcnt)
605816f7b76SBarry Smith {
606816f7b76SBarry Smith   PetscErrorCode ierr;
607816f7b76SBarry Smith   MPI_Comm       comm;
608816f7b76SBarry Smith   PetscFunctionBegin;
609816f7b76SBarry Smith   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
610816f7b76SBarry Smith   while (PETSC_TRUE) {
611816f7b76SBarry Smith     ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr);
612816f7b76SBarry Smith     if (!*mcnt) break;
613816f7b76SBarry Smith   }
614816f7b76SBarry Smith   PetscFunctionReturn(0);
615816f7b76SBarry Smith }
616