Actual source code: amsopen.c


  2: #include <petsc/private/viewerimpl.h>
  3: #include <petscviewersaws.h>

  5: /*@C
  6:     PetscViewerSAWsOpen - Opens an SAWs `PetscViewer`.

  8:     Collective; No Fortran Support

 10:     Input Parameter:
 11: .   comm - the MPI communicator

 13:     Output Parameter:
 14: .   lab - the `PetscViewer`

 16:     Options Database Keys:
 17: +   -saws_port <port number> - port number where you are running SAWs client
 18: .   -xxx_view saws - publish the object xxx
 19: -   -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
 20:                     the user unblocks the problem with an external tool that access the object with SAWS

 22:     Level: advanced

 24:     Notes:
 25:     Unlike other viewers that only access the object being viewed on the call to `XXXView`(object,viewer) the SAWs viewer allows
 26:     one to view the object asynchronously as the program continues to run. One can remove SAWs access to the object with a call to
 27:     `PetscObjectSAWsViewOff()`.

 29:     Information about the SAWs is available via https://bitbucket.org/saws/saws

 31: .seealso: [](sec_viewers), `PetscViewerDestroy()`, `PetscViewerStringSPrintf()`, `PETSC_VIEWER_SAWS_()`, `PetscObjectSAWsBlock()`,
 32:           `PetscObjectSAWsViewOff()`, `PetscObjectSAWsTakeAccess()`, `PetscObjectSAWsGrantAccess()`
 33: @*/
 34: PetscErrorCode PetscViewerSAWsOpen(MPI_Comm comm, PetscViewer *lab)
 35: {
 36:   PetscFunctionBegin;
 37:   PetscCall(PetscViewerCreate(comm, lab));
 38:   PetscCall(PetscViewerSetType(*lab, PETSCVIEWERSAWS));
 39:   PetscFunctionReturn(PETSC_SUCCESS);
 40: }

 42: /*@C
 43:    PetscObjectViewSAWs - View the base portion of any object with an SAWs viewer

 45:    Collective

 47:    Input Parameters:
 48: +  obj - the `PetscObject` variable. Thus must be cast with a (`PetscObject`), for example, `PetscObjectSetName`((`PetscObject`)mat,name);
 49: -  viewer - the SAWs viewer

 51:    Level: advanced

 53:    Note:
 54:    The object must have already been named before calling this routine since naming an
 55:    object can be collective.

 57:    Developer Note:
 58:    Currently this is called only on MPI rank 0 of `PETSC_COMM_WORLD`

 60: .seealso: [](sec_viewers), `PetscViewer`, `PetscObject`, `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`
 61: @*/
 62: PetscErrorCode PetscObjectViewSAWs(PetscObject obj, PetscViewer viewer)
 63: {
 64:   char        dir[1024];
 65:   PetscMPIInt rank;

 67:   PetscFunctionBegin;
 69:   if (obj->amsmem) PetscFunctionReturn(PETSC_SUCCESS);
 70:   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
 71:   PetscCheck(rank == 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Should only be being called on rank zero");
 72:   PetscCheck(obj->name, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Object must already have been named");

 74:   obj->amsmem = PETSC_TRUE;
 75:   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Objects/%s/Class", obj->name));
 76:   PetscCallSAWs(SAWs_Register, (dir, &obj->class_name, 1, SAWs_READ, SAWs_STRING));
 77:   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Objects/%s/Type", obj->name));
 78:   PetscCallSAWs(SAWs_Register, (dir, &obj->type_name, 1, SAWs_READ, SAWs_STRING));
 79:   PetscCall(PetscSNPrintf(dir, 1024, "/PETSc/Objects/%s/__Id", obj->name));
 80:   PetscCallSAWs(SAWs_Register, (dir, &obj->id, 1, SAWs_READ, SAWs_INT));
 81:   PetscFunctionReturn(PETSC_SUCCESS);
 82: }