xref: /petsc/src/sys/classes/viewer/impls/ams/amsopen.c (revision f05ece33fd483fcf0ae47f3ecf85fefd993a83b6)
15c6c1daeSBarry Smith 
207475bc1SBarry Smith #include <petsc-private/viewerimpl.h>   /*I  "petscsys.h"  */
338dc1537SBarry Smith #include <petscviewerams.h>
45c6c1daeSBarry Smith 
55c6c1daeSBarry Smith #undef __FUNCT__
65c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerAMSOpen"
75c6c1daeSBarry Smith /*@C
85c6c1daeSBarry Smith     PetscViewerAMSOpen - Opens an AMS memory snooper PetscViewer.
95c6c1daeSBarry Smith 
105c6c1daeSBarry Smith     Collective on MPI_Comm
115c6c1daeSBarry Smith 
125c6c1daeSBarry Smith     Input Parameters:
135c6c1daeSBarry Smith +   comm - the MPI communicator
14*f05ece33SBarry Smith -   name - name of AMS communicator being created if NULL is passed defaults to PETSc
155c6c1daeSBarry Smith 
165c6c1daeSBarry Smith     Output Parameter:
175c6c1daeSBarry Smith .   lab - the PetscViewer
185c6c1daeSBarry Smith 
195c6c1daeSBarry Smith     Options Database Keys:
205c6c1daeSBarry Smith +   -ams_port <port number> - port number where you are running AMS client
21*f05ece33SBarry Smith .   -xxx_view ams - publish the object xxx
22*f05ece33SBarry Smith .   -xxx_ams_block - blocks the program at the end of a critical point (for KSP and SNES it is the end of a solve) until
23*f05ece33SBarry Smith                     the user unblocks the the problem with an external tool that access the object with the AMS
245c6c1daeSBarry Smith -   -ams_java - open JAVA AMS client
255c6c1daeSBarry Smith 
265c6c1daeSBarry Smith     Level: advanced
275c6c1daeSBarry Smith 
285c6c1daeSBarry Smith     Fortran Note:
295c6c1daeSBarry Smith     This routine is not supported in Fortran.
305c6c1daeSBarry Smith 
315c6c1daeSBarry Smith     See the matlab/petsc directory in the AMS installation for one example of external
325c6c1daeSBarry Smith     tools that can monitor PETSc objects that have been published.
335c6c1daeSBarry Smith 
345c6c1daeSBarry Smith     Notes:
35*f05ece33SBarry Smith     Unlike other viewers that only access the object being viewed on the call to XXXView(object,viewer) the AMS viewer allows
36*f05ece33SBarry Smith     one to view the object asynchronously as the program continues to run. One can remove AMS access to the object with a call to
37*f05ece33SBarry Smith     PetscObjectAMSViewOff().
3838dc1537SBarry Smith 
395c6c1daeSBarry Smith     Information about the AMS is available via http://www.mcs.anl.gov/ams.
405c6c1daeSBarry Smith 
415c6c1daeSBarry Smith    Concepts: AMS
42*f05ece33SBarry Smith    Concepts: Argonne Memory Snooper
435c6c1daeSBarry Smith    Concepts: Asynchronous Memory Snooper
445c6c1daeSBarry Smith 
45*f05ece33SBarry Smith .seealso: PetscViewerDestroy(), PetscViewerStringSPrintf(), PETSC_VIEWER_AMS_(), PetscObjectAMSBlock(),
46*f05ece33SBarry Smith           PetscObjectAMSViewOff(), PetscObjectAMSTakeAccess(), PetscObjectAMSGrantAccess()
475c6c1daeSBarry Smith 
485c6c1daeSBarry Smith @*/
495c6c1daeSBarry Smith PetscErrorCode PetscViewerAMSOpen(MPI_Comm comm,const char name[],PetscViewer *lab)
505c6c1daeSBarry Smith {
515c6c1daeSBarry Smith   PetscErrorCode ierr;
525c6c1daeSBarry Smith 
535c6c1daeSBarry Smith   PetscFunctionBegin;
545c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr);
555c6c1daeSBarry Smith   ierr = PetscViewerSetType(*lab,PETSCVIEWERAMS);CHKERRQ(ierr);
565c6c1daeSBarry Smith   ierr = PetscViewerAMSSetCommName(*lab,name);CHKERRQ(ierr);
575c6c1daeSBarry Smith   PetscFunctionReturn(0);
585c6c1daeSBarry Smith }
59bfb97211SBarry Smith 
60bfb97211SBarry Smith #undef __FUNCT__
61bfb97211SBarry Smith #define __FUNCT__ "PetscObjectViewAMS"
62bfb97211SBarry Smith /*@C
63bfb97211SBarry Smith    PetscObjectViewAMS - View the base portion of any object with an AMS viewer
64bfb97211SBarry Smith 
65bfb97211SBarry Smith    Collective on PetscObject
66bfb97211SBarry Smith 
67bfb97211SBarry Smith    Input Parameters:
68bfb97211SBarry Smith +  obj - the Petsc variable
69bfb97211SBarry Smith          Thus must be cast with a (PetscObject), for example,
70bfb97211SBarry Smith          PetscObjectSetName((PetscObject)mat,name);
71bfb97211SBarry Smith -  viewer - the AMS viewer
72bfb97211SBarry Smith 
73bfb97211SBarry Smith    Level: advanced
74bfb97211SBarry Smith 
75bfb97211SBarry Smith    Concepts: publishing object
76bfb97211SBarry Smith 
77*f05ece33SBarry Smith .seealso: PetscObjectSetName(), PetscObjectAMSViewOff()
78bfb97211SBarry Smith 
79bfb97211SBarry Smith @*/
80bfb97211SBarry Smith PetscErrorCode  PetscObjectViewAMS(PetscObject obj,PetscViewer viewer)
81bfb97211SBarry Smith {
82bfb97211SBarry Smith   PetscErrorCode ierr;
83bfb97211SBarry Smith   AMS_Memory     amem;
84bfb97211SBarry Smith   AMS_Comm       acomm;
85bfb97211SBarry Smith 
86bfb97211SBarry Smith   PetscFunctionBegin;
87bfb97211SBarry Smith   PetscValidHeader(obj,1);
88bfb97211SBarry Smith   if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(0);
89bfb97211SBarry Smith   if (obj->amsmem != -1) PetscFunctionReturn(0);
90bfb97211SBarry Smith   ierr = PetscObjectName(obj);CHKERRQ(ierr);
91bfb97211SBarry Smith 
92bfb97211SBarry Smith   ierr = PetscViewerAMSGetAMSComm(viewer,&acomm);CHKERRQ(ierr);
93*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_create,(acomm,obj->name,&amem));
94bfb97211SBarry Smith   obj->amsmem = (int)amem;
95bfb97211SBarry Smith 
96*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_take_access,(amem));
97*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_add_field,(amem,"Class",&obj->class_name,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF));
98*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_add_field,(amem,"Type",&obj->type_name,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF));
99*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_add_field,(amem,"Id",&obj->id,1,AMS_INT,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF));
100*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_add_field,(amem,"ParentId",&obj->parentid,1,AMS_INT,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF));
101*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_add_field,(amem,"Name",&obj->name,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF));
102*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_add_field,(amem,"Block",&obj->amspublishblock,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF));
103*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_publish,(amem));
104*f05ece33SBarry Smith   PetscStackCallAMS(AMS_Memory_grant_access,(amem));
105bfb97211SBarry Smith   PetscFunctionReturn(0);
106bfb97211SBarry Smith }
107