xref: /petsc/src/sys/classes/viewer/impls/ams/amsopen.c (revision 98d129c30f3ee9fdddc40fdbc5a989b7be64f888)
1 #include <petsc/private/viewerimpl.h> /*I  "petscsys.h"  */
2 #include <petscviewersaws.h>
3 
4 /*@C
5   PetscViewerSAWsOpen - Opens an SAWs `PetscViewer`.
6 
7   Collective; No Fortran Support
8 
9   Input Parameter:
10 . comm - the MPI communicator
11 
12   Output Parameter:
13 . lab - the `PetscViewer`
14 
15   Options Database Keys:
16 + -saws_port <port number> - port number where you are running SAWs client
17 . -xxx_view saws           - publish the object xxx
18 - -xxx_saws_block          - blocks the program at the end of a critical point (for `KSP` and `SNES` it is the end of a solve) until
19                     the user unblocks the problem with an external tool that access the object with SAWS
20 
21   Level: advanced
22 
23   Notes:
24   Unlike other viewers that only access the object being viewed on the call to `XXXView`(object,viewer) the SAWs viewer allows
25   one to view the object asynchronously as the program continues to run. One can remove SAWs access to the object with a call to
26   `PetscObjectSAWsViewOff()`.
27 
28   Information about the SAWs is available via https://bitbucket.org/saws/saws
29 
30 .seealso: [](sec_viewers), `PetscViewerDestroy()`, `PetscViewerStringSPrintf()`, `PETSC_VIEWER_SAWS_()`, `PetscObjectSAWsBlock()`,
31           `PetscObjectSAWsViewOff()`, `PetscObjectSAWsTakeAccess()`, `PetscObjectSAWsGrantAccess()`
32 @*/
33 PetscErrorCode PetscViewerSAWsOpen(MPI_Comm comm, PetscViewer *lab)
34 {
35   PetscFunctionBegin;
36   PetscCall(PetscViewerCreate(comm, lab));
37   PetscCall(PetscViewerSetType(*lab, PETSCVIEWERSAWS));
38   PetscFunctionReturn(PETSC_SUCCESS);
39 }
40 
41 /*@C
42   PetscObjectViewSAWs - View the base portion of any object with an SAWs viewer
43 
44   Collective
45 
46   Input Parameters:
47 + obj    - the `PetscObject` variable. It must be cast with a (`PetscObject`), for example, `PetscObjectSetName`((`PetscObject`)mat,name);
48 - viewer - the SAWs viewer
49 
50   Level: advanced
51 
52   Note:
53   The object must have already been named before calling this routine since naming an
54   object can be collective.
55 
56   Developer Notes:
57   Currently this is called only on MPI rank 0 of `PETSC_COMM_WORLD`
58 
59 .seealso: [](sec_viewers), `PetscViewer`, `PetscObject`, `PetscObjectSetName()`
60 @*/
61 PetscErrorCode PetscObjectViewSAWs(PetscObject obj, PetscViewer viewer)
62 {
63   char        dir[1024];
64   PetscMPIInt rank;
65 
66   PetscFunctionBegin;
67   PetscValidHeader(obj, 1);
68   if (obj->amsmem) PetscFunctionReturn(PETSC_SUCCESS);
69   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
70   PetscCheck(rank == 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Should only be being called on rank zero");
71   PetscCheck(obj->name, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Object must already have been named");
72 
73   obj->amsmem = PETSC_TRUE;
74   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Objects/%s/Class", obj->name));
75   PetscCallSAWs(SAWs_Register, (dir, &obj->class_name, 1, SAWs_READ, SAWs_STRING));
76   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Objects/%s/Type", obj->name));
77   PetscCallSAWs(SAWs_Register, (dir, &obj->type_name, 1, SAWs_READ, SAWs_STRING));
78   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Objects/%s/__Id", obj->name));
79   PetscCallSAWs(SAWs_Register, (dir, &obj->id, 1, SAWs_READ, SAWs_INT));
80   PetscFunctionReturn(PETSC_SUCCESS);
81 }
82