xref: /petsc/src/sys/classes/viewer/impls/ascii/vcreatea.c (revision 48a46eb9bd028bec07ec0f396b1a3abb43f14558)
15c6c1daeSBarry Smith 
2f5860696SSatish Balay #include <../src/sys/classes/viewer/impls/ascii/asciiimpl.h> /*I     "petscviewer.h"   I*/
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
55c6c1daeSBarry Smith 
6e2dcd6d3SBarry Smith /*
7e2dcd6d3SBarry Smith     The variable Petsc_Viewer_Stdout_keyval is used to indicate an MPI attribute that
8e2dcd6d3SBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
9e2dcd6d3SBarry Smith */
10d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Stdout_keyval = MPI_KEYVAL_INVALID;
11e2dcd6d3SBarry Smith 
129c5ded49SBarry Smith /*@
135c6c1daeSBarry Smith    PetscViewerASCIIGetStdout - Creates a ASCII PetscViewer shared by all processors
145c6c1daeSBarry Smith                     in a communicator. Error returning version of PETSC_VIEWER_STDOUT_()
155c6c1daeSBarry Smith 
16d083f849SBarry Smith    Collective
175c6c1daeSBarry Smith 
185c6c1daeSBarry Smith    Input Parameter:
195c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
205c6c1daeSBarry Smith 
215c6c1daeSBarry Smith    Level: beginner
225c6c1daeSBarry Smith 
235c6c1daeSBarry Smith    Notes:
245c6c1daeSBarry Smith      This should be used in all PETSc source code instead of PETSC_VIEWER_STDOUT_()
255c6c1daeSBarry Smith 
26db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_()`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDERR_`, `PETSC_VIEWER_STDOUT_WORLD`,
27db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_SELF`
285c6c1daeSBarry Smith 
295c6c1daeSBarry Smith @*/
309371c9d4SSatish Balay PetscErrorCode PetscViewerASCIIGetStdout(MPI_Comm comm, PetscViewer *viewer) {
31e2dcd6d3SBarry Smith   PetscBool flg;
32e2dcd6d3SBarry Smith   MPI_Comm  ncomm;
335c6c1daeSBarry Smith 
345c6c1daeSBarry Smith   PetscFunctionBegin;
359566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockStdout));
369566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm, &ncomm, NULL));
37*48a46eb9SPierre Jolivet   if (Petsc_Viewer_Stdout_keyval == MPI_KEYVAL_INVALID) PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN, MPI_COMM_NULL_DELETE_FN, &Petsc_Viewer_Stdout_keyval, NULL));
389566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(ncomm, Petsc_Viewer_Stdout_keyval, (void **)viewer, (PetscMPIInt *)&flg));
39e2dcd6d3SBarry Smith   if (!flg) { /* PetscViewer not yet created */
409566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIOpen(ncomm, "stdout", viewer));
419566063dSJacob Faibussowitsch     PetscCall(PetscObjectRegisterDestroy((PetscObject)*viewer));
429566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(ncomm, Petsc_Viewer_Stdout_keyval, (void *)*viewer));
43e2dcd6d3SBarry Smith   }
449566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&ncomm));
459566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockStdout));
465c6c1daeSBarry Smith   PetscFunctionReturn(0);
475c6c1daeSBarry Smith }
485c6c1daeSBarry Smith 
495c6c1daeSBarry Smith /*@C
505c6c1daeSBarry Smith    PETSC_VIEWER_STDOUT_ - Creates a ASCII PetscViewer shared by all processors
515c6c1daeSBarry Smith                     in a communicator.
525c6c1daeSBarry Smith 
53d083f849SBarry Smith    Collective
545c6c1daeSBarry Smith 
555c6c1daeSBarry Smith    Input Parameter:
565c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
575c6c1daeSBarry Smith 
585c6c1daeSBarry Smith    Level: beginner
595c6c1daeSBarry Smith 
605c6c1daeSBarry Smith    Notes:
615c6c1daeSBarry Smith    Unlike almost all other PETSc routines, this does not return
625c6c1daeSBarry Smith    an error code. Usually used in the form
635c6c1daeSBarry Smith $      XXXView(XXX object,PETSC_VIEWER_STDOUT_(comm));
645c6c1daeSBarry Smith 
65db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_()`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDERR_`, `PETSC_VIEWER_STDOUT_WORLD`,
66db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_SELF`
675c6c1daeSBarry Smith 
685c6c1daeSBarry Smith @*/
699371c9d4SSatish Balay PetscViewer PETSC_VIEWER_STDOUT_(MPI_Comm comm) {
705c6c1daeSBarry Smith   PetscErrorCode ierr;
715c6c1daeSBarry Smith   PetscViewer    viewer;
725c6c1daeSBarry Smith 
735c6c1daeSBarry Smith   PetscFunctionBegin;
745c6c1daeSBarry Smith   ierr = PetscViewerASCIIGetStdout(comm, &viewer);
759371c9d4SSatish Balay   if (ierr) {
769371c9d4SSatish Balay     PetscError(PETSC_COMM_SELF, __LINE__, "PETSC_VIEWER_STDOUT_", __FILE__, PETSC_ERR_PLIB, PETSC_ERROR_INITIAL, " ");
779371c9d4SSatish Balay     PetscFunctionReturn(NULL);
789371c9d4SSatish Balay   }
795c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
805c6c1daeSBarry Smith }
815c6c1daeSBarry Smith 
825c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
835c6c1daeSBarry Smith 
84e2dcd6d3SBarry Smith /*
85e2dcd6d3SBarry Smith     The variable Petsc_Viewer_Stderr_keyval is used to indicate an MPI attribute that
86e2dcd6d3SBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
87e2dcd6d3SBarry Smith */
88d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Stderr_keyval = MPI_KEYVAL_INVALID;
89e2dcd6d3SBarry Smith 
909c5ded49SBarry Smith /*@
915c6c1daeSBarry Smith    PetscViewerASCIIGetStderr - Creates a ASCII PetscViewer shared by all processors
925c6c1daeSBarry Smith                     in a communicator. Error returning version of PETSC_VIEWER_STDERR_()
935c6c1daeSBarry Smith 
94d083f849SBarry Smith    Collective
955c6c1daeSBarry Smith 
965c6c1daeSBarry Smith    Input Parameter:
975c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
985c6c1daeSBarry Smith 
995c6c1daeSBarry Smith    Level: beginner
1005c6c1daeSBarry Smith 
1015c6c1daeSBarry Smith    Notes:
1025c6c1daeSBarry Smith      This should be used in all PETSc source code instead of PETSC_VIEWER_STDERR_()
1035c6c1daeSBarry Smith 
104db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_()`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDERR_`, `PETSC_VIEWER_STDERR_WORLD`,
105db781477SPatrick Sanan           `PETSC_VIEWER_STDERR_SELF`
1065c6c1daeSBarry Smith 
1075c6c1daeSBarry Smith @*/
1089371c9d4SSatish Balay PetscErrorCode PetscViewerASCIIGetStderr(MPI_Comm comm, PetscViewer *viewer) {
109e2dcd6d3SBarry Smith   PetscBool flg;
110e2dcd6d3SBarry Smith   MPI_Comm  ncomm;
111e2dcd6d3SBarry Smith 
112e2dcd6d3SBarry Smith   PetscFunctionBegin;
1139566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockStderr));
1149566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm, &ncomm, NULL));
115*48a46eb9SPierre Jolivet   if (Petsc_Viewer_Stderr_keyval == MPI_KEYVAL_INVALID) PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN, MPI_COMM_NULL_DELETE_FN, &Petsc_Viewer_Stderr_keyval, NULL));
1169566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(ncomm, Petsc_Viewer_Stderr_keyval, (void **)viewer, (PetscMPIInt *)&flg));
117e2dcd6d3SBarry Smith   if (!flg) { /* PetscViewer not yet created */
1189566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIOpen(ncomm, "stderr", viewer));
1199566063dSJacob Faibussowitsch     PetscCall(PetscObjectRegisterDestroy((PetscObject)*viewer));
1209566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(ncomm, Petsc_Viewer_Stderr_keyval, (void *)*viewer));
121e2dcd6d3SBarry Smith   }
1229566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&ncomm));
1239566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockStderr));
1245c6c1daeSBarry Smith   PetscFunctionReturn(0);
1255c6c1daeSBarry Smith }
1265c6c1daeSBarry Smith 
1275c6c1daeSBarry Smith /*@C
1285c6c1daeSBarry Smith    PETSC_VIEWER_STDERR_ - Creates a ASCII PetscViewer shared by all processors
1295c6c1daeSBarry Smith                     in a communicator.
1305c6c1daeSBarry Smith 
131d083f849SBarry Smith    Collective
1325c6c1daeSBarry Smith 
1335c6c1daeSBarry Smith    Input Parameter:
1345c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
1355c6c1daeSBarry Smith 
1365c6c1daeSBarry Smith    Level: beginner
1375c6c1daeSBarry Smith 
1385c6c1daeSBarry Smith    Note:
1395c6c1daeSBarry Smith    Unlike almost all other PETSc routines, this does not return
1405c6c1daeSBarry Smith    an error code. Usually used in the form
1415c6c1daeSBarry Smith $      XXXView(XXX object,PETSC_VIEWER_STDERR_(comm));
1425c6c1daeSBarry Smith 
143db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDOUT_`, `PETSC_VIEWER_STDOUT_WORLD`,
144db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_SELF`, `PETSC_VIEWER_STDERR_WORLD`, `PETSC_VIEWER_STDERR_SELF`
1455c6c1daeSBarry Smith @*/
1469371c9d4SSatish Balay PetscViewer PETSC_VIEWER_STDERR_(MPI_Comm comm) {
1475c6c1daeSBarry Smith   PetscErrorCode ierr;
1485c6c1daeSBarry Smith   PetscViewer    viewer;
1495c6c1daeSBarry Smith 
1505c6c1daeSBarry Smith   PetscFunctionBegin;
1515c6c1daeSBarry Smith   ierr = PetscViewerASCIIGetStderr(comm, &viewer);
1529371c9d4SSatish Balay   if (ierr) {
1539371c9d4SSatish Balay     PetscError(PETSC_COMM_SELF, __LINE__, "PETSC_VIEWER_STDERR_", __FILE__, PETSC_ERR_PLIB, PETSC_ERROR_INITIAL, " ");
1549371c9d4SSatish Balay     PetscFunctionReturn(NULL);
1559371c9d4SSatish Balay   }
1565c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
1575c6c1daeSBarry Smith }
1585c6c1daeSBarry Smith 
1595c6c1daeSBarry Smith PetscMPIInt                     Petsc_Viewer_keyval = MPI_KEYVAL_INVALID;
1605c6c1daeSBarry Smith /*
1615c6c1daeSBarry Smith    Called with MPI_Comm_free() is called on a communicator that has a viewer as an attribute. The viewer is not actually destroyed because that is managed by
1625c6c1daeSBarry Smith    PetscObjectDestroyRegisterAll(). PetscViewerASCIIGetStdout() registers the viewer with PetscObjectDestroyRegister() to be destroyed when PetscFinalize() is called.
1635c6c1daeSBarry Smith 
1645c6c1daeSBarry Smith   This is called by MPI, not by users.
1655c6c1daeSBarry Smith 
1665c6c1daeSBarry Smith */
1679371c9d4SSatish Balay PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelViewer(MPI_Comm comm, PetscMPIInt keyval, void *attr_val, void *extra_state) {
1685c6c1daeSBarry Smith   PetscFunctionBegin;
1699566063dSJacob Faibussowitsch   PetscCallMPI(PetscInfo(NULL, "Removing viewer data attribute in an MPI_Comm %ld\n", (long)comm));
1705c6c1daeSBarry Smith   PetscFunctionReturn(MPI_SUCCESS);
1715c6c1daeSBarry Smith }
1725c6c1daeSBarry Smith 
1735c6c1daeSBarry Smith /*@C
174f8859db6SBarry Smith    PetscViewerASCIIOpen - Opens an ASCII file for writing as a PetscViewer.
1755c6c1daeSBarry Smith 
176d083f849SBarry Smith    Collective
1775c6c1daeSBarry Smith 
1785c6c1daeSBarry Smith    Input Parameters:
1795c6c1daeSBarry Smith +  comm - the communicator
1805c6c1daeSBarry Smith -  name - the file name
1815c6c1daeSBarry Smith 
1825c6c1daeSBarry Smith    Output Parameter:
1835c6c1daeSBarry Smith .  lab - the PetscViewer to use with the specified file
1845c6c1daeSBarry Smith 
1855c6c1daeSBarry Smith    Level: beginner
1865c6c1daeSBarry Smith 
1875c6c1daeSBarry Smith    Notes:
188f8859db6SBarry Smith    To open a ASCII file as a viewer for reading one must use the sequence
189f8859db6SBarry Smith $     PetscViewerCreate(comm,&lab);
190f8859db6SBarry Smith $     PetscViewerSetType(lab,PETSCVIEWERASCII);
191f8859db6SBarry Smith $     PetscViewerFileSetMode(lab,FILE_MODE_READ);
192f8859db6SBarry Smith $     PetscViewerFileSetName(lab,name);
193f8859db6SBarry Smith 
1945c6c1daeSBarry Smith    This PetscViewer can be destroyed with PetscViewerDestroy().
1955c6c1daeSBarry Smith 
1962ea3bc1cSBarry Smith    The MPI communicator used here must match that used by the object one is viewing. For example if the
1972ea3bc1cSBarry Smith    Mat was created with a PETSC_COMM_WORLD, then the Viewer must be created with PETSC_COMM_WORLD
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith    As shown below, PetscViewerASCIIOpen() is useful in conjunction with
2005c6c1daeSBarry Smith    MatView() and VecView()
2015c6c1daeSBarry Smith .vb
2025c6c1daeSBarry Smith      PetscViewerASCIIOpen(PETSC_COMM_WORLD,"mat.output",&viewer);
2035c6c1daeSBarry Smith      MatView(matrix,viewer);
2045c6c1daeSBarry Smith .ve
2055c6c1daeSBarry Smith 
206db781477SPatrick Sanan .seealso: `MatView()`, `VecView()`, `PetscViewerDestroy()`, `PetscViewerBinaryOpen()`, `PetscViewerASCIIRead()`
207db781477SPatrick Sanan           `PetscViewerASCIIGetPointer()`, `PetscViewerPushFormat()`, `PETSC_VIEWER_STDOUT_`, `PETSC_VIEWER_STDERR_`,
208db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_WORLD`, `PETSC_VIEWER_STDOUT_SELF`,
2095c6c1daeSBarry Smith @*/
2109371c9d4SSatish Balay PetscErrorCode PetscViewerASCIIOpen(MPI_Comm comm, const char name[], PetscViewer *lab) {
2115c6c1daeSBarry Smith   PetscViewerLink *vlink, *nv;
2125c6c1daeSBarry Smith   PetscBool        flg, eq;
2135c6c1daeSBarry Smith   size_t           len;
2145c6c1daeSBarry Smith 
2155c6c1daeSBarry Smith   PetscFunctionBegin;
2169566063dSJacob Faibussowitsch   PetscCall(PetscStrlen(name, &len));
2175c6c1daeSBarry Smith   if (!len) {
2189566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIGetStdout(comm, lab));
2199566063dSJacob Faibussowitsch     PetscCall(PetscObjectReference((PetscObject)*lab));
2205c6c1daeSBarry Smith     PetscFunctionReturn(0);
2215c6c1daeSBarry Smith   }
2229566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockOpen));
223*48a46eb9SPierre Jolivet   if (Petsc_Viewer_keyval == MPI_KEYVAL_INVALID) PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN, Petsc_DelViewer, &Petsc_Viewer_keyval, (void *)0));
2242bf49c77SBarry Smith   /*
2252bf49c77SBarry Smith        It would be better to move this code to PetscFileSetName() but since it must return a preexiting communicator
2262bf49c77SBarry Smith      we cannot do that, since PetscFileSetName() takes a communicator that already exists.
2272bf49c77SBarry Smith 
2282bf49c77SBarry Smith       Plus if the original communicator that created the file has since been close this will not detect the old
2292bf49c77SBarry Smith       communictor and hence will overwrite the old data. It may be better to simply remove all this code
2302bf49c77SBarry Smith   */
2315c6c1daeSBarry Smith   /* make sure communicator is a PETSc communicator */
2329566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm, &comm, NULL));
2335c6c1daeSBarry Smith   /* has file already been opened into a viewer */
2349566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(comm, Petsc_Viewer_keyval, (void **)&vlink, (PetscMPIInt *)&flg));
2355c6c1daeSBarry Smith   if (flg) {
2365c6c1daeSBarry Smith     while (vlink) {
2379566063dSJacob Faibussowitsch       PetscCall(PetscStrcmp(name, ((PetscViewer_ASCII *)(vlink->viewer->data))->filename, &eq));
2385c6c1daeSBarry Smith       if (eq) {
2399566063dSJacob Faibussowitsch         PetscCall(PetscObjectReference((PetscObject)vlink->viewer));
2405c6c1daeSBarry Smith         *lab = vlink->viewer;
2419566063dSJacob Faibussowitsch         PetscCall(PetscCommDestroy(&comm));
2429566063dSJacob Faibussowitsch         PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockOpen));
2435c6c1daeSBarry Smith         PetscFunctionReturn(0);
2445c6c1daeSBarry Smith       }
2455c6c1daeSBarry Smith       vlink = vlink->next;
2465c6c1daeSBarry Smith     }
2475c6c1daeSBarry Smith   }
2489566063dSJacob Faibussowitsch   PetscCall(PetscViewerCreate(comm, lab));
2499566063dSJacob Faibussowitsch   PetscCall(PetscViewerSetType(*lab, PETSCVIEWERASCII));
2501baa6e33SBarry Smith   if (name) PetscCall(PetscViewerFileSetName(*lab, name));
2515c6c1daeSBarry Smith   /* save viewer into communicator if needed later */
2529566063dSJacob Faibussowitsch   PetscCall(PetscNew(&nv));
2535c6c1daeSBarry Smith   nv->viewer = *lab;
2545c6c1daeSBarry Smith   if (!flg) {
2559566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(comm, Petsc_Viewer_keyval, nv));
2565c6c1daeSBarry Smith   } else {
2579566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_get_attr(comm, Petsc_Viewer_keyval, (void **)&vlink, (PetscMPIInt *)&flg));
2585c6c1daeSBarry Smith     if (vlink) {
2595c6c1daeSBarry Smith       while (vlink->next) vlink = vlink->next;
2605c6c1daeSBarry Smith       vlink->next = nv;
2615c6c1daeSBarry Smith     } else {
2629566063dSJacob Faibussowitsch       PetscCallMPI(MPI_Comm_set_attr(comm, Petsc_Viewer_keyval, nv));
2635c6c1daeSBarry Smith     }
2645c6c1daeSBarry Smith   }
2659566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&comm));
2669566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockOpen));
2675c6c1daeSBarry Smith   PetscFunctionReturn(0);
2685c6c1daeSBarry Smith }
2695c6c1daeSBarry Smith 
2705c6c1daeSBarry Smith /*@C
2715c6c1daeSBarry Smith    PetscViewerASCIIOpenWithFILE - Given an open file creates an ASCII viewer that prints to it.
2725c6c1daeSBarry Smith 
273d083f849SBarry Smith    Collective
2745c6c1daeSBarry Smith 
2755c6c1daeSBarry Smith    Input Parameters:
2765c6c1daeSBarry Smith +  comm - the communicator
2775c6c1daeSBarry Smith -  fd - the FILE pointer
2785c6c1daeSBarry Smith 
2795c6c1daeSBarry Smith    Output Parameter:
2805c6c1daeSBarry Smith .  lab - the PetscViewer to use with the specified file
2815c6c1daeSBarry Smith 
2825c6c1daeSBarry Smith    Level: beginner
2835c6c1daeSBarry Smith 
2845c6c1daeSBarry Smith    Notes:
2855c6c1daeSBarry Smith    This PetscViewer can be destroyed with PetscViewerDestroy(), but the fd will NOT be closed.
2865c6c1daeSBarry Smith 
2875c6c1daeSBarry Smith    If a multiprocessor communicator is used (such as PETSC_COMM_WORLD),
2885c6c1daeSBarry Smith    then only the first processor in the group uses the file.  All other
2895c6c1daeSBarry Smith    processors send their data to the first processor to print.
2905c6c1daeSBarry Smith 
291db781477SPatrick Sanan .seealso: `MatView()`, `VecView()`, `PetscViewerDestroy()`, `PetscViewerBinaryOpen()`,
292db781477SPatrick Sanan           `PetscViewerASCIIGetPointer()`, `PetscViewerPushFormat()`, `PETSC_VIEWER_STDOUT_`, `PETSC_VIEWER_STDERR_`,
293db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_WORLD`, `PETSC_VIEWER_STDOUT_SELF`, `PetscViewerASCIIOpen()`
2945c6c1daeSBarry Smith @*/
2959371c9d4SSatish Balay PetscErrorCode PetscViewerASCIIOpenWithFILE(MPI_Comm comm, FILE *fd, PetscViewer *lab) {
2965c6c1daeSBarry Smith   PetscFunctionBegin;
2979566063dSJacob Faibussowitsch   PetscCall(PetscViewerCreate(comm, lab));
2989566063dSJacob Faibussowitsch   PetscCall(PetscViewerSetType(*lab, PETSCVIEWERASCII));
2999566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIISetFILE(*lab, fd));
3005c6c1daeSBarry Smith   PetscFunctionReturn(0);
3015c6c1daeSBarry Smith }
3025c6c1daeSBarry Smith 
3039371c9d4SSatish Balay PetscErrorCode PetscViewerASCIISetFILE(PetscViewer viewer, FILE *fd) {
3045c6c1daeSBarry Smith   PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data;
3055c6c1daeSBarry Smith 
3065c6c1daeSBarry Smith   PetscFunctionBegin;
3075c6c1daeSBarry Smith   vascii->fd        = fd;
3085c6c1daeSBarry Smith   vascii->closefile = PETSC_FALSE;
3095c6c1daeSBarry Smith   PetscFunctionReturn(0);
3105c6c1daeSBarry Smith }
311