Actual source code: pams.c

petsc-3.11.4 2019-09-28
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:    Concepts: publishing object

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

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

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

 35:    Collective on PetscObject

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

 42:    Level: advanced

 44:    Concepts: publishing object

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

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

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

 61:    Not Collective

 63:    Level: advanced

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

 67: @*/
 68: PetscErrorCode  PetscSAWsBlock(void)
 69: {
 70:   PetscErrorCode     ierr;
 71:   volatile PetscBool block = PETSC_TRUE;

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

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

 91:    Collective on PetscObject

 93:    Input Parameters:
 94: .  obj - the Petsc variable
 95:          Thus must be cast with a (PetscObject), for example,
 96:          PetscObjectSetName((PetscObject)mat,name);


 99:    Level: advanced

101:    Concepts: publishing object

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

105: @*/
106: PetscErrorCode  PetscObjectSAWsBlock(PetscObject obj)
107: {
108:   PetscErrorCode     ierr;


113:   if (!obj->amspublishblock || !obj->amsmem) return(0);
114:   PetscSAWsBlock();
115:   return(0);
116: }

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

121:    Collective on PetscObject

123:    Input Parameters:
124: +  obj - the Petsc variable
125:          Thus must be cast with a (PetscObject), for example,
126:          PetscObjectSetName((PetscObject)mat,name);
127: -  flg - whether it should block

129:    Level: advanced

131:    Concepts: publishing object

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

135: @*/
136: PetscErrorCode  PetscObjectSAWsSetBlock(PetscObject obj,PetscBool flg)
137: {
140:   obj->amspublishblock = flg;
141:   return(0);
142: }

144: PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj)
145: {
146:   char           dir[1024];

150:   if (obj->classid == PETSC_VIEWER_CLASSID) return(0);
151:   if (!obj->amsmem) return(0);
152:   PetscSNPrintf(dir,1024,"/PETSc/Objects/%s",obj->name);
153:   PetscStackCallSAWs(SAWs_Delete,(dir));
154:   return(0);
155: }