Actual source code: pams.c

petsc-3.7.7 2017-09-25
Report Typos and Errors
  2: #include <petsc/private/petscimpl.h>        /*I    "petscsys.h"   I*/
  3: #include <petscviewersaws.h>
  4: #include <petscsys.h>

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

 11:    Collective on PetscObject

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

 18:    Level: advanced

 20:    Concepts: publishing object

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

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

 36: /*@C
 37:    PetscObjectSAWsGrantAccess - Grants access of the data fields that have been published to SAWs to the memory snooper to change

 39:    Collective on PetscObject

 41:    Input Parameters:
 42: .  obj - the Petsc variable
 43:          Thus must be cast with a (PetscObject), for example,
 44:          PetscObjectSetName((PetscObject)mat,name);

 46:    Level: advanced

 48:    Concepts: publishing object

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

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

 64: /*@C
 65:    PetscSAWsBlock - Blocks on SAWs until a client unblocks

 67:    Not Collective 

 69:    Level: advanced

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

 73: @*/
 74: PetscErrorCode  PetscSAWsBlock(void)
 75: {
 76:   PetscErrorCode     ierr;
 77:   volatile PetscBool block = PETSC_TRUE;

 80:   PetscStackCallSAWs(SAWs_Register,("__Block",(PetscBool*)&block,1,SAWs_WRITE,SAWs_BOOLEAN));
 81:   SAWs_Lock();
 82:   while (block) {
 83:     SAWs_Unlock();
 84:     PetscInfo(NULL,"Blocking on SAWs\n");
 85:     PetscSleep(.3);
 86:     SAWs_Lock();
 87:   }
 88:   SAWs_Unlock();
 89:   PetscStackCallSAWs(SAWs_Delete,("__Block"));
 90:   PetscInfo(NULL,"Out of SAWs block\n");
 91:   return(0);
 92: }

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

 99:    Collective on PetscObject

101:    Input Parameters:
102: .  obj - the Petsc variable
103:          Thus must be cast with a (PetscObject), for example,
104:          PetscObjectSetName((PetscObject)mat,name);


107:    Level: advanced

109:    Concepts: publishing object

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

113: @*/
114: PetscErrorCode  PetscObjectSAWsBlock(PetscObject obj)
115: {
116:   PetscErrorCode     ierr;


121:   if (!obj->amspublishblock || !obj->amsmem) return(0);
122:   PetscSAWsBlock();
123:   return(0);
124: }

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

131:    Collective on PetscObject

133:    Input Parameters:
134: +  obj - the Petsc variable
135:          Thus must be cast with a (PetscObject), for example,
136:          PetscObjectSetName((PetscObject)mat,name);
137: -  flg - whether it should block

139:    Level: advanced

141:    Concepts: publishing object

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

145: @*/
146: PetscErrorCode  PetscObjectSAWsSetBlock(PetscObject obj,PetscBool flg)
147: {
150:   obj->amspublishblock = flg;
151:   return(0);
152: }

156: PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj)
157: {
158:   char           dir[1024];

162:   if (obj->classid == PETSC_VIEWER_CLASSID) return(0);
163:   if (!obj->amsmem) return(0);
164:   PetscSNPrintf(dir,1024,"/PETSc/Objects/%s",obj->name);
165:   PetscStackCallSAWs(SAWs_Delete,(dir));
166:   return(0);
167: }