Actual source code: pams.c
petsc-3.13.6 2020-09-29
Report Typos and Errors

      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);

     95:    Level: advanced

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

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

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

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

    115:    Collective on PetscObject

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

    123:    Level: advanced

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

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

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

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