xref: /petsc/src/sys/classes/viewer/impls/ams/amsopen.c (revision 56f85f323450cf9debdeb7ce96ecfa9f4a7fcf30)
15c6c1daeSBarry Smith 
207475bc1SBarry Smith #include <petsc-private/viewerimpl.h>   /*I  "petscsys.h"  */
3e04113cfSBarry Smith #include <petscviewersaws.h>
45c6c1daeSBarry Smith 
55c6c1daeSBarry Smith #undef __FUNCT__
6e04113cfSBarry Smith #define __FUNCT__ "PetscViewerSAWsOpen"
75c6c1daeSBarry Smith /*@C
8d45a07a7SBarry Smith     PetscViewerSAWsOpen - Opens an SAWs PetscViewer.
95c6c1daeSBarry Smith 
105c6c1daeSBarry Smith     Collective on MPI_Comm
115c6c1daeSBarry Smith 
125c6c1daeSBarry Smith     Input Parameters:
13ec957eceSBarry Smith .   comm - the MPI communicator
145c6c1daeSBarry Smith 
155c6c1daeSBarry Smith     Output Parameter:
165c6c1daeSBarry Smith .   lab - the PetscViewer
175c6c1daeSBarry Smith 
185c6c1daeSBarry Smith     Options Database Keys:
19e04113cfSBarry Smith +   -ams_port <port number> - port number where you are running SAWs client
20f05ece33SBarry Smith .   -xxx_view ams - publish the object xxx
21e04113cfSBarry Smith -   -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
22f05ece33SBarry Smith                     the user unblocks the the problem with an external tool that access the object with the AMS
235c6c1daeSBarry Smith 
245c6c1daeSBarry Smith     Level: advanced
255c6c1daeSBarry Smith 
265c6c1daeSBarry Smith     Fortran Note:
275c6c1daeSBarry Smith     This routine is not supported in Fortran.
285c6c1daeSBarry Smith 
295c6c1daeSBarry Smith 
305c6c1daeSBarry Smith     Notes:
31e04113cfSBarry Smith     Unlike other viewers that only access the object being viewed on the call to XXXView(object,viewer) the SAWs viewer allows
32e04113cfSBarry Smith     one to view the object asynchronously as the program continues to run. One can remove SAWs access to the object with a call to
33e04113cfSBarry Smith     PetscObjectSAWsViewOff().
3438dc1537SBarry Smith 
35d45a07a7SBarry Smith     Information about the SAWs is available via http://bitbucket.org/saws/saws
365c6c1daeSBarry Smith 
37e04113cfSBarry Smith .seealso: PetscViewerDestroy(), PetscViewerStringSPrintf(), PETSC_VIEWER_SAWS_(), PetscObjectSAWsBlock(),
38e04113cfSBarry Smith           PetscObjectSAWsViewOff(), PetscObjectSAWsTakeAccess(), PetscObjectSAWsGrantAccess()
395c6c1daeSBarry Smith 
405c6c1daeSBarry Smith @*/
41e04113cfSBarry Smith PetscErrorCode PetscViewerSAWsOpen(MPI_Comm comm,PetscViewer *lab)
425c6c1daeSBarry Smith {
435c6c1daeSBarry Smith   PetscErrorCode ierr;
445c6c1daeSBarry Smith 
455c6c1daeSBarry Smith   PetscFunctionBegin;
465c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr);
47e04113cfSBarry Smith   ierr = PetscViewerSetType(*lab,PETSCVIEWERSAWS);CHKERRQ(ierr);
485c6c1daeSBarry Smith   PetscFunctionReturn(0);
495c6c1daeSBarry Smith }
50bfb97211SBarry Smith 
51bfb97211SBarry Smith #undef __FUNCT__
52e04113cfSBarry Smith #define __FUNCT__ "PetscObjectViewSAWs"
53bfb97211SBarry Smith /*@C
54e04113cfSBarry Smith    PetscObjectViewSAWs - View the base portion of any object with an SAWs viewer
55bfb97211SBarry Smith 
56bfb97211SBarry Smith    Collective on PetscObject
57bfb97211SBarry Smith 
58bfb97211SBarry Smith    Input Parameters:
59bfb97211SBarry Smith +  obj - the Petsc variable
60bfb97211SBarry Smith          Thus must be cast with a (PetscObject), for example,
61bfb97211SBarry Smith          PetscObjectSetName((PetscObject)mat,name);
62e04113cfSBarry Smith -  viewer - the SAWs viewer
63bfb97211SBarry Smith 
64bfb97211SBarry Smith    Level: advanced
65bfb97211SBarry Smith 
66bfb97211SBarry Smith    Concepts: publishing object
67bfb97211SBarry Smith 
68d45a07a7SBarry Smith    Developer Note: Currently this is called only on rank zero of PETSC_COMM_WORLD
69d45a07a7SBarry Smith 
70d45a07a7SBarry Smith    The object must have already been named before calling this routine since naming an
71d45a07a7SBarry Smith    object can be collective.
72d45a07a7SBarry Smith 
73d45a07a7SBarry Smith 
74e04113cfSBarry Smith .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff()
75bfb97211SBarry Smith 
76bfb97211SBarry Smith @*/
77e04113cfSBarry Smith PetscErrorCode  PetscObjectViewSAWs(PetscObject obj,PetscViewer viewer)
78bfb97211SBarry Smith {
79bfb97211SBarry Smith   PetscErrorCode ierr;
802657e9d9SBarry Smith   char           dir[1024];
81d45a07a7SBarry Smith   PetscMPIInt    rank;
82bfb97211SBarry Smith 
83bfb97211SBarry Smith   PetscFunctionBegin;
84bfb97211SBarry Smith   PetscValidHeader(obj,1);
85ec957eceSBarry Smith   if (obj->amsmem) PetscFunctionReturn(0);
86d45a07a7SBarry Smith   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
87d45a07a7SBarry Smith   if (rank) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Should only be being called on rank zero");
88d45a07a7SBarry Smith   if (!obj->name) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Object must already have been named");
89bfb97211SBarry Smith 
90*56f85f32SBarry Smith   obj->amsmem = PETSC_TRUE;
912657e9d9SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/Class",obj->name);CHKERRQ(ierr);
922657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&obj->class_name,1,SAWs_READ,SAWs_STRING));
932657e9d9SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/Type",obj->name);CHKERRQ(ierr);
942657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&obj->type_name,1,SAWs_READ,SAWs_STRING));
95b8a862caSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/_Id",obj->name);CHKERRQ(ierr);
962657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&obj->id,1,SAWs_READ,SAWs_INT));
97b8a862caSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/_ParentID",obj->name);CHKERRQ(ierr);
982657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&obj->parentid,1,SAWs_READ,SAWs_INT));
99b8a862caSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/_Publish_Block",obj->name);CHKERRQ(ierr);
1002657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&obj->amspublishblock,1,SAWs_READ,SAWs_BOOLEAN));
1012657e9d9SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/Block",obj->name);CHKERRQ(ierr);
1022657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&obj->amsblock,1,SAWs_WRITE,SAWs_BOOLEAN));
103bfb97211SBarry Smith   PetscFunctionReturn(0);
104bfb97211SBarry Smith }
105