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 - name - name of AMS communicator being created if NULL is passed defaults to PETSc 15 16 Output Parameter: 17 . lab - the PetscViewer 18 19 Options Database Keys: 20 + -ams_port <port number> - port number where you are running AMS client 21 . -xxx_view ams - publish the object xxx 22 . -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 the user unblocks the the problem with an external tool that access the object with the AMS 24 - -ams_java - open JAVA AMS client 25 26 Level: advanced 27 28 Fortran Note: 29 This routine is not supported in Fortran. 30 31 See the matlab/petsc directory in the AMS installation for one example of external 32 tools that can monitor PETSc objects that have been published. 33 34 Notes: 35 Unlike other viewers that only access the object being viewed on the call to XXXView(object,viewer) the AMS viewer allows 36 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 PetscObjectAMSViewOff(). 38 39 Information about the AMS is available via http://www.mcs.anl.gov/ams. 40 41 Concepts: AMS 42 Concepts: Argonne Memory Snooper 43 Concepts: Asynchronous Memory Snooper 44 45 .seealso: PetscViewerDestroy(), PetscViewerStringSPrintf(), PETSC_VIEWER_AMS_(), PetscObjectAMSBlock(), 46 PetscObjectAMSViewOff(), PetscObjectAMSTakeAccess(), PetscObjectAMSGrantAccess() 47 48 @*/ 49 PetscErrorCode PetscViewerAMSOpen(MPI_Comm comm,const char name[],PetscViewer *lab) 50 { 51 PetscErrorCode ierr; 52 53 PetscFunctionBegin; 54 ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr); 55 ierr = PetscViewerSetType(*lab,PETSCVIEWERAMS);CHKERRQ(ierr); 56 ierr = PetscViewerAMSSetCommName(*lab,name);CHKERRQ(ierr); 57 PetscFunctionReturn(0); 58 } 59 60 #undef __FUNCT__ 61 #define __FUNCT__ "PetscObjectViewAMS" 62 /*@C 63 PetscObjectViewAMS - View the base portion of any object with an AMS viewer 64 65 Collective on PetscObject 66 67 Input Parameters: 68 + obj - the Petsc variable 69 Thus must be cast with a (PetscObject), for example, 70 PetscObjectSetName((PetscObject)mat,name); 71 - viewer - the AMS viewer 72 73 Level: advanced 74 75 Concepts: publishing object 76 77 .seealso: PetscObjectSetName(), PetscObjectAMSViewOff() 78 79 @*/ 80 PetscErrorCode PetscObjectViewAMS(PetscObject obj,PetscViewer viewer) 81 { 82 PetscErrorCode ierr; 83 AMS_Memory amem; 84 AMS_Comm acomm; 85 86 PetscFunctionBegin; 87 PetscValidHeader(obj,1); 88 if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(0); 89 if (obj->amsmem != -1) PetscFunctionReturn(0); 90 ierr = PetscObjectName(obj);CHKERRQ(ierr); 91 92 ierr = PetscViewerAMSGetAMSComm(viewer,&acomm);CHKERRQ(ierr); 93 PetscStackCallAMS(AMS_Memory_create,(acomm,obj->name,&amem)); 94 obj->amsmem = (int)amem; 95 96 PetscStackCallAMS(AMS_Memory_take_access,(amem)); 97 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Class",&obj->class_name,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 98 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Type",&obj->type_name,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 99 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Id",&obj->id,1,AMS_INT,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 100 PetscStackCallAMS(AMS_Memory_add_field,(amem,"ParentId",&obj->parentid,1,AMS_INT,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 101 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Name",&obj->name,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 102 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Publish Block",&obj->amspublishblock,1,AMS_BOOLEAN,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF)); 103 PetscStackCallAMS(AMS_Memory_add_field,(amem,"Block",&obj->amsblock,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF)); 104 PetscStackCallAMS(AMS_Memory_publish,(amem)); 105 PetscStackCallAMS(AMS_Memory_grant_access,(amem)); 106 PetscFunctionReturn(0); 107 } 108