xref: /petsc/src/sys/classes/viewer/impls/ams/amsopen.c (revision ec957ece147126e1303fa8daf36bd57228a49e96)
1 
2 #include <petsc-private/viewerimpl.h>   /*I  "petscsys.h"  */
3 #include <petscviewerams.h>
4 
5 #undef __FUNCT__
6 #define __FUNCT__ "PetscViewerAMSOpen"
7 /*@C
8     PetscViewerAMSOpen - Opens an AMS memory snooper 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 +   -ams_port <port number> - port number where you are running AMS client
20 .   -xxx_view ams - publish the object xxx
21 -   -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
22                     the user unblocks the the problem with an external tool that access the object with the AMS
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 AMS viewer allows
32     one to view the object asynchronously as the program continues to run. One can remove AMS access to the object with a call to
33     PetscObjectAMSViewOff().
34 
35     Information about the AMS is available via http://www.mcs.anl.gov/ams.
36 
37    Concepts: AMS
38    Concepts: Argonne Memory Snooper
39    Concepts: Asynchronous Memory Snooper
40 
41 .seealso: PetscViewerDestroy(), PetscViewerStringSPrintf(), PETSC_VIEWER_AMS_(), PetscObjectAMSBlock(),
42           PetscObjectAMSViewOff(), PetscObjectAMSTakeAccess(), PetscObjectAMSGrantAccess()
43 
44 @*/
45 PetscErrorCode PetscViewerAMSOpen(MPI_Comm comm,PetscViewer *lab)
46 {
47   PetscErrorCode ierr;
48 
49   PetscFunctionBegin;
50   ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr);
51   ierr = PetscViewerSetType(*lab,PETSCVIEWERAMS);CHKERRQ(ierr);
52   PetscFunctionReturn(0);
53 }
54 
55 #undef __FUNCT__
56 #define __FUNCT__ "PetscObjectViewAMS"
57 /*@C
58    PetscObjectViewAMS - View the base portion of any object with an AMS viewer
59 
60    Collective on PetscObject
61 
62    Input Parameters:
63 +  obj - the Petsc variable
64          Thus must be cast with a (PetscObject), for example,
65          PetscObjectSetName((PetscObject)mat,name);
66 -  viewer - the AMS viewer
67 
68    Level: advanced
69 
70    Concepts: publishing object
71 
72 .seealso: PetscObjectSetName(), PetscObjectAMSViewOff()
73 
74 @*/
75 PetscErrorCode  PetscObjectViewAMS(PetscObject obj,PetscViewer viewer)
76 {
77   PetscErrorCode ierr;
78 
79   PetscFunctionBegin;
80   PetscValidHeader(obj,1);
81   if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(0);
82   if (obj->amsmem) PetscFunctionReturn(0);
83   ierr = PetscObjectName(obj);CHKERRQ(ierr);
84 
85   PetscStackCallAMS(AMS_Memory_Create,(obj->name,&obj->amsmem));
86   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"Class",&obj->class_name,1,AMS_READ,AMS_STRING));
87   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"Type",&obj->type_name,1,AMS_READ,AMS_STRING));
88   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"Id",&obj->id,1,AMS_READ,AMS_INT));
89   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"ParentId",&obj->parentid,1,AMS_READ,AMS_INT));
90   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"Name",&obj->name,1,AMS_READ,AMS_STRING));
91   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"Publish Block",&obj->amspublishblock,1,AMS_READ,AMS_BOOLEAN));
92   PetscStackCallAMS(AMS_New_Field,(obj->amsmem,"Block",&obj->amsblock,1,AMS_WRITE,AMS_BOOLEAN));
93   PetscFunctionReturn(0);
94 }
95