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