Date: 2022-03-04T17:37:18+00:00

Actual source code: pams.c

      2: #include <petsc/private/petscimpl.h>
      3: #include <petscviewersaws.h>
      4: #include <petscsys.h>

      6: /*@C
      7:    PetscObjectSAWsTakeAccess - Take access of the data fields that have been published to SAWs so they may be changed locally

      9:    Collective on PetscObject

     11:    Input Parameters:
     12: .  obj - the Petsc variable
     13:          Thus must be cast with a (PetscObject), for example,
     14:          PetscObjectSetName((PetscObject)mat,name);

     16:    Level: advanced

     18: .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff(), PetscObjectSAWsGrantAccess()

     20: @*/
     21: PetscErrorCode  PetscObjectSAWsTakeAccess(PetscObject obj)
     22: {
     23:   if (obj->amsmem) {
     24:     /* cannot wrap with PetscPushStack() because that also deals with the locks */
     25:     SAWs_Lock();
     26:   }
     27:   return 0;
     28: }

     30: /*@C
     31:    PetscObjectSAWsGrantAccess - Grants access of the data fields that have been published to SAWs to change

     33:    Collective on PetscObject

     35:    Input Parameters:
     36: .  obj - the Petsc variable
     37:          Thus must be cast with a (PetscObject), for example,
     38:          PetscObjectSetName((PetscObject)mat,name);

     40:    Level: advanced

     42: .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff(), PetscObjectSAWsTakeAccess()

     44: @*/
     45: PetscErrorCode  PetscObjectSAWsGrantAccess(PetscObject obj)
     46: {
     47:   if (obj->amsmem) {
     48:     /* cannot wrap with PetscPushStack() because that also deals with the locks */
     49:     SAWs_Unlock();
     50:   }
     51:   return 0;
     52: }

     54: /*@C
     55:    PetscSAWsBlock - Blocks on SAWs until a client (person using the web browser) unblocks

     57:    Not Collective

     59:    Level: advanced

     61: .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff(), PetscObjectSAWsSetBlock(), PetscObjectSAWsBlock()

     63: @*/
     64: PetscErrorCode  PetscSAWsBlock(void)
     65: {
     66:   PetscErrorCode     ierr;
     67:   volatile PetscBool block = PETSC_TRUE;

     70:   PetscStackCallSAWs(SAWs_Register,("__Block",(PetscBool*)&block,1,SAWs_WRITE,SAWs_BOOLEAN));
     71:   SAWs_Lock();
     72:   while (block) {
     73:     SAWs_Unlock();
     74:     PetscInfo(NULL,"Blocking on SAWs\n");
     75:     PetscSleep(.3);
     76:     SAWs_Lock();
     77:   }
     78:   SAWs_Unlock();
     79:   PetscStackCallSAWs(SAWs_Delete,("__Block"));
     80:   PetscInfo(NULL,"Out of SAWs block\n");
     81:   return(0);
     82: }

     84: /*@C
     85:    PetscObjectSAWsBlock - Blocks the object if PetscObjectSAWsSetBlock() has been called

     87:    Collective on PetscObject

     89:    Input Parameters:
     90: .  obj - the Petsc variable
     91:          Thus must be cast with a (PetscObject), for example,
     92:          PetscObjectSetName((PetscObject)mat,name);

     94:    Level: advanced

     96: .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff(), PetscObjectSAWsSetBlock()

     98: @*/
     99: PetscErrorCode  PetscObjectSAWsBlock(PetscObject obj)
    100: {
    101:   PetscErrorCode     ierr;

    106:   if (!obj->amspublishblock || !obj->amsmem) return(0);
    107:   PetscSAWsBlock();
    108:   return(0);
    109: }

    111: /*@C
    112:    PetscObjectSAWsSetBlock - Sets whether an object will block at PetscObjectSAWsBlock()

    114:    Collective on PetscObject

    116:    Input Parameters:
    117: +  obj - the Petsc variable
    118:          Thus must be cast with a (PetscObject), for example,
    119:          PetscObjectSetName((PetscObject)mat,name);
    120: -  flg - whether it should block

    122:    Level: advanced

    124: .seealso: PetscObjectSetName(), PetscObjectSAWsViewOff(), PetscObjectSAWsBlock()

    126: @*/
    127: PetscErrorCode  PetscObjectSAWsSetBlock(PetscObject obj,PetscBool flg)
    128: {
    131:   obj->amspublishblock = flg;
    132:   return(0);
    133: }

    135: PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj)
    136: {
    137:   char           dir[1024];

    141:   if (obj->classid == PETSC_VIEWER_CLASSID) return(0);
    142:   if (!obj->amsmem) return(0);
    143:   PetscSNPrintf(dir,1024,"/PETSc/Objects/%s",obj->name);
    144:   PetscStackCallSAWs(SAWs_Delete,(dir));
    145:   return(0);
    146: }