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:   volatile PetscBool block = PETSC_TRUE;

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

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

 85:    Collective on PetscObject

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

 92:    Level: advanced

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

 96: @*/
 97: PetscErrorCode  PetscObjectSAWsBlock(PetscObject obj)
 98: {

101:   if (!obj->amspublishblock || !obj->amsmem) return 0;
102:   PetscSAWsBlock();
103:   return 0;
104: }

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

109:    Collective on PetscObject

111:    Input Parameters:
112: +  obj - the Petsc variable
113:          Thus must be cast with a (PetscObject), for example,
114:          PetscObjectSetName((PetscObject)mat,name);
115: -  flg - whether it should block

117:    Level: advanced

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

121: @*/
122: PetscErrorCode  PetscObjectSAWsSetBlock(PetscObject obj,PetscBool flg)
123: {
125:   obj->amspublishblock = flg;
126:   return 0;
127: }

129: PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj)
130: {
131:   char dir[PETSC_MAX_PATH_LEN];

133:   if (obj->classid == PETSC_VIEWER_CLASSID) return 0;
134:   if (!obj->amsmem) return 0;
135:   PetscSNPrintf(dir,sizeof(dir),"/PETSc/Objects/%s",obj->name);
136:   PetscStackCallSAWs(SAWs_Delete,(dir));
137:   return 0;
138: }