Date: 2026-07-30T21:14:23+00:00

Actual source code: amsopen.c

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

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

      7:   Collective; No Fortran Support

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

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

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

     21:   Level: advanced

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

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

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

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

     44:   Collective

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

     50:   Level: advanced

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

     56:   Developer Notes:
     57:   Currently this is called only on MPI rank 0 of `PETSC_COMM_WORLD`

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

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

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