1b3506946SBarry Smith 2af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 3e04113cfSBarry Smith #include <petscviewersaws.h> 4ec7429eaSBarry Smith #include <petscsys.h> 5b3506946SBarry Smith 6ec7429eaSBarry Smith /*@C 7*811af0c4SBarry Smith PetscObjectSAWsTakeAccess - Take access of the data fields that have been published to SAWs by a `PetscObject` so their values may 8*811af0c4SBarry Smith be changed in the computation 9ec7429eaSBarry Smith 10*811af0c4SBarry Smith Collective on obj 11ec7429eaSBarry Smith 12ec7429eaSBarry Smith Input Parameters: 13*811af0c4SBarry Smith . obj - the `PetscObject` variable. This must be cast with a (`PetscObject`), for example, `PetscObjectSAWSTakeAccess`((`PetscObject`)mat); 14ec7429eaSBarry Smith 15ec7429eaSBarry Smith Level: advanced 16ec7429eaSBarry Smith 17*811af0c4SBarry Smith Developer Note: 18*811af0c4SBarry Smith The naming should perhaps be changed to `PetscObjectSAWsGetAccess()` and `PetscObjectSAWsRestoreAccess()` 19ec7429eaSBarry Smith 20*811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsGrantAccess()` 21ec7429eaSBarry Smith @*/ 229371c9d4SSatish Balay PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject obj) { 23ec957eceSBarry Smith if (obj->amsmem) { 2416ad0300SBarry Smith /* cannot wrap with PetscPushStack() because that also deals with the locks */ 259a492a5cSBarry Smith SAWs_Lock(); 26ec7429eaSBarry Smith } 2767a1e3b6SBarry Smith return 0; 28ec7429eaSBarry Smith } 29ec7429eaSBarry Smith 30ec7429eaSBarry Smith /*@C 31*811af0c4SBarry Smith PetscObjectSAWsGrantAccess - Grants access of the data fields that have been published to SAWs called when the changes made during 32*811af0c4SBarry Smith `PetscObjectSAWsTakeAccess()` are complete. This allows the webserve to change the published values. 33ec7429eaSBarry Smith 34*811af0c4SBarry Smith Collective on obj 35ec7429eaSBarry Smith 36ec7429eaSBarry Smith Input Parameters: 37*811af0c4SBarry Smith . obj - the `PetscObject` variable. This must be cast with a (`PetscObject`), for example, `PetscObjectSAWSRestoreAccess`((`PetscObject`)mat); 38ec7429eaSBarry Smith 39ec7429eaSBarry Smith Level: advanced 40ec7429eaSBarry Smith 41db781477SPatrick Sanan .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsTakeAccess()` 42ec7429eaSBarry Smith @*/ 439371c9d4SSatish Balay PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject obj) { 44ec957eceSBarry Smith if (obj->amsmem) { 4516ad0300SBarry Smith /* cannot wrap with PetscPushStack() because that also deals with the locks */ 469a492a5cSBarry Smith SAWs_Unlock(); 47ec7429eaSBarry Smith } 4867a1e3b6SBarry Smith return 0; 49ec7429eaSBarry Smith } 50ec7429eaSBarry Smith 517aab2a10SBarry Smith /*@C 52*811af0c4SBarry Smith PetscSAWsBlock - Blocks on SAWs until a client (person using the web browser) unblocks it 537aab2a10SBarry Smith 547aab2a10SBarry Smith Not Collective 557aab2a10SBarry Smith 567aab2a10SBarry Smith Level: advanced 577aab2a10SBarry Smith 58db781477SPatrick Sanan .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsSetBlock()`, `PetscObjectSAWsBlock()` 597aab2a10SBarry Smith @*/ 609371c9d4SSatish Balay PetscErrorCode PetscSAWsBlock(void) { 617aab2a10SBarry Smith volatile PetscBool block = PETSC_TRUE; 627aab2a10SBarry Smith 637aab2a10SBarry Smith PetscFunctionBegin; 64792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, ("__Block", (PetscBool *)&block, 1, SAWs_WRITE, SAWs_BOOLEAN)); 657aab2a10SBarry Smith SAWs_Lock(); 667aab2a10SBarry Smith while (block) { 677aab2a10SBarry Smith SAWs_Unlock(); 689566063dSJacob Faibussowitsch PetscCall(PetscInfo(NULL, "Blocking on SAWs\n")); 699566063dSJacob Faibussowitsch PetscCall(PetscSleep(.3)); 707aab2a10SBarry Smith SAWs_Lock(); 717aab2a10SBarry Smith } 727aab2a10SBarry Smith SAWs_Unlock(); 73792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, ("__Block")); 749566063dSJacob Faibussowitsch PetscCall(PetscInfo(NULL, "Out of SAWs block\n")); 757aab2a10SBarry Smith PetscFunctionReturn(0); 767aab2a10SBarry Smith } 777aab2a10SBarry Smith 78b90c6cbeSBarry Smith /*@C 79*811af0c4SBarry Smith PetscObjectSAWsBlock - Blocks the object if `PetscObjectSAWsSetBlock()` has been called 80b90c6cbeSBarry Smith 81*811af0c4SBarry Smith Collective on obj 82b90c6cbeSBarry Smith 83b90c6cbeSBarry Smith Input Parameters: 84*811af0c4SBarry Smith . obj - the PETSc variable 85b90c6cbeSBarry Smith 86b90c6cbeSBarry Smith Level: advanced 87b90c6cbeSBarry Smith 88*811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsSetBlock()`, `PetscSAWsBlock()` 89b90c6cbeSBarry Smith @*/ 909371c9d4SSatish Balay PetscErrorCode PetscObjectSAWsBlock(PetscObject obj) { 91b90c6cbeSBarry Smith PetscFunctionBegin; 92b90c6cbeSBarry Smith PetscValidHeader(obj, 1); 93b90c6cbeSBarry Smith 9496f8ada6SBarry Smith if (!obj->amspublishblock || !obj->amsmem) PetscFunctionReturn(0); 959566063dSJacob Faibussowitsch PetscCall(PetscSAWsBlock()); 96b90c6cbeSBarry Smith PetscFunctionReturn(0); 97b90c6cbeSBarry Smith } 98b90c6cbeSBarry Smith 99b90c6cbeSBarry Smith /*@C 100*811af0c4SBarry Smith PetscObjectSAWsSetBlock - Sets whether an object will block at `PetscObjectSAWsBlock()` 101b90c6cbeSBarry Smith 102*811af0c4SBarry Smith Collective on obj 103b90c6cbeSBarry Smith 104b90c6cbeSBarry Smith Input Parameters: 105*811af0c4SBarry Smith + obj - the PETSc variable 106b90c6cbeSBarry Smith - flg - whether it should block 107b90c6cbeSBarry Smith 108b90c6cbeSBarry Smith Level: advanced 109b90c6cbeSBarry Smith 110*811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsBlock()`, `PetscSAWsBlock()` 111b90c6cbeSBarry Smith @*/ 1129371c9d4SSatish Balay PetscErrorCode PetscObjectSAWsSetBlock(PetscObject obj, PetscBool flg) { 113b90c6cbeSBarry Smith PetscFunctionBegin; 114b90c6cbeSBarry Smith PetscValidHeader(obj, 1); 115b90c6cbeSBarry Smith obj->amspublishblock = flg; 116b90c6cbeSBarry Smith PetscFunctionReturn(0); 117b90c6cbeSBarry Smith } 118b90c6cbeSBarry Smith 1199371c9d4SSatish Balay PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj) { 1205f80ce2aSJacob Faibussowitsch char dir[PETSC_MAX_PATH_LEN]; 1219a492a5cSBarry Smith 12292e62aa6SBarry Smith PetscFunctionBegin; 1239fb22e1aSBarry Smith if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(0); 12416ad0300SBarry Smith if (!obj->amsmem) PetscFunctionReturn(0); 1259566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, sizeof(dir), "/PETSc/Objects/%s", obj->name)); 126792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, (dir)); 12792e62aa6SBarry Smith PetscFunctionReturn(0); 12892e62aa6SBarry Smith } 129