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