xref: /petsc/src/sys/classes/viewer/impls/ams/amsopen.c (revision 7d5fd1e4d9337468ad3f05b65b7facdcd2dfd2a4)
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   PetscErrorCode ierr;
41 
42   PetscFunctionBegin;
43   ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr);
44   ierr = PetscViewerSetType(*lab,PETSCVIEWERSAWS);CHKERRQ(ierr);
45   PetscFunctionReturn(0);
46 }
47 
48 /*@C
49    PetscObjectViewSAWs - View the base portion of any object with an SAWs viewer
50 
51    Collective on PetscObject
52 
53    Input Parameters:
54 +  obj - the Petsc variable
55          Thus must be cast with a (PetscObject), for example,
56          PetscObjectSetName((PetscObject)mat,name);
57 -  viewer - the SAWs viewer
58 
59    Level: advanced
60 
61    Developer Note: Currently this is called only on rank zero of PETSC_COMM_WORLD
62 
63    The object must have already been named before calling this routine since naming an
64    object can be collective.
65 
66 .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff()
67 
68 @*/
69 PetscErrorCode  PetscObjectViewSAWs(PetscObject obj,PetscViewer viewer)
70 {
71   PetscErrorCode ierr;
72   char           dir[1024];
73   PetscMPIInt    rank;
74 
75   PetscFunctionBegin;
76   PetscValidHeader(obj,1);
77   if (obj->amsmem) PetscFunctionReturn(0);
78   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRMPI(ierr);
79   if (rank) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Should only be being called on rank zero");
80   if (!obj->name) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Object must already have been named");
81 
82   obj->amsmem = PETSC_TRUE;
83   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/Class",obj->name);CHKERRQ(ierr);
84   PetscStackCallSAWs(SAWs_Register,(dir,&obj->class_name,1,SAWs_READ,SAWs_STRING));
85   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/Type",obj->name);CHKERRQ(ierr);
86   PetscStackCallSAWs(SAWs_Register,(dir,&obj->type_name,1,SAWs_READ,SAWs_STRING));
87   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/__Id",obj->name);CHKERRQ(ierr);
88   PetscStackCallSAWs(SAWs_Register,(dir,&obj->id,1,SAWs_READ,SAWs_INT));
89   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/__ParentID",obj->name);CHKERRQ(ierr);
90   PetscStackCallSAWs(SAWs_Register,(dir,&obj->parentid,1,SAWs_READ,SAWs_INT));
91   PetscFunctionReturn(0);
92 }
93