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 7811af0c4SBarry Smith PetscObjectSAWsTakeAccess - Take access of the data fields that have been published to SAWs by a `PetscObject` so their values may 8811af0c4SBarry Smith be changed in the computation 9ec7429eaSBarry Smith 10c3339decSBarry Smith Collective 11ec7429eaSBarry Smith 12*2fe279fdSBarry Smith Input Parameter: 13811af0c4SBarry 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 17811af0c4SBarry Smith Developer Note: 18811af0c4SBarry Smith The naming should perhaps be changed to `PetscObjectSAWsGetAccess()` and `PetscObjectSAWsRestoreAccess()` 19ec7429eaSBarry Smith 20811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsGrantAccess()` 21ec7429eaSBarry Smith @*/ 22d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject obj) 23d71ae5a4SJacob Faibussowitsch { 24ec957eceSBarry Smith if (obj->amsmem) { 2516ad0300SBarry Smith /* cannot wrap with PetscPushStack() because that also deals with the locks */ 269a492a5cSBarry Smith SAWs_Lock(); 27ec7429eaSBarry Smith } 283ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 29ec7429eaSBarry Smith } 30ec7429eaSBarry Smith 31ec7429eaSBarry Smith /*@C 32811af0c4SBarry Smith PetscObjectSAWsGrantAccess - Grants access of the data fields that have been published to SAWs called when the changes made during 33811af0c4SBarry Smith `PetscObjectSAWsTakeAccess()` are complete. This allows the webserve to change the published values. 34ec7429eaSBarry Smith 35c3339decSBarry Smith Collective 36ec7429eaSBarry Smith 37*2fe279fdSBarry Smith Input Parameter: 38811af0c4SBarry Smith . obj - the `PetscObject` variable. This must be cast with a (`PetscObject`), for example, `PetscObjectSAWSRestoreAccess`((`PetscObject`)mat); 39ec7429eaSBarry Smith 40ec7429eaSBarry Smith Level: advanced 41ec7429eaSBarry Smith 42db781477SPatrick Sanan .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsTakeAccess()` 43ec7429eaSBarry Smith @*/ 44d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject obj) 45d71ae5a4SJacob Faibussowitsch { 46ec957eceSBarry Smith if (obj->amsmem) { 4716ad0300SBarry Smith /* cannot wrap with PetscPushStack() because that also deals with the locks */ 489a492a5cSBarry Smith SAWs_Unlock(); 49ec7429eaSBarry Smith } 503ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 51ec7429eaSBarry Smith } 52ec7429eaSBarry Smith 537aab2a10SBarry Smith /*@C 54811af0c4SBarry Smith PetscSAWsBlock - Blocks on SAWs until a client (person using the web browser) unblocks it 557aab2a10SBarry Smith 567aab2a10SBarry Smith Not Collective 577aab2a10SBarry Smith 587aab2a10SBarry Smith Level: advanced 597aab2a10SBarry Smith 60db781477SPatrick Sanan .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsSetBlock()`, `PetscObjectSAWsBlock()` 617aab2a10SBarry Smith @*/ 62d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSAWsBlock(void) 63d71ae5a4SJacob Faibussowitsch { 647aab2a10SBarry Smith volatile PetscBool block = PETSC_TRUE; 657aab2a10SBarry Smith 667aab2a10SBarry Smith PetscFunctionBegin; 67792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, ("__Block", (PetscBool *)&block, 1, SAWs_WRITE, SAWs_BOOLEAN)); 687aab2a10SBarry Smith SAWs_Lock(); 697aab2a10SBarry Smith while (block) { 707aab2a10SBarry Smith SAWs_Unlock(); 719566063dSJacob Faibussowitsch PetscCall(PetscInfo(NULL, "Blocking on SAWs\n")); 729566063dSJacob Faibussowitsch PetscCall(PetscSleep(.3)); 737aab2a10SBarry Smith SAWs_Lock(); 747aab2a10SBarry Smith } 757aab2a10SBarry Smith SAWs_Unlock(); 76792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, ("__Block")); 779566063dSJacob Faibussowitsch PetscCall(PetscInfo(NULL, "Out of SAWs block\n")); 783ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 797aab2a10SBarry Smith } 807aab2a10SBarry Smith 81b90c6cbeSBarry Smith /*@C 82811af0c4SBarry Smith PetscObjectSAWsBlock - Blocks the object if `PetscObjectSAWsSetBlock()` has been called 83b90c6cbeSBarry Smith 84c3339decSBarry Smith Collective 85b90c6cbeSBarry Smith 86*2fe279fdSBarry Smith Input Parameter: 87811af0c4SBarry Smith . obj - the PETSc variable 88b90c6cbeSBarry Smith 89b90c6cbeSBarry Smith Level: advanced 90b90c6cbeSBarry Smith 91811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsSetBlock()`, `PetscSAWsBlock()` 92b90c6cbeSBarry Smith @*/ 93d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsBlock(PetscObject obj) 94d71ae5a4SJacob Faibussowitsch { 95b90c6cbeSBarry Smith PetscFunctionBegin; 96b90c6cbeSBarry Smith PetscValidHeader(obj, 1); 97b90c6cbeSBarry Smith 983ba16761SJacob Faibussowitsch if (!obj->amspublishblock || !obj->amsmem) PetscFunctionReturn(PETSC_SUCCESS); 999566063dSJacob Faibussowitsch PetscCall(PetscSAWsBlock()); 1003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 101b90c6cbeSBarry Smith } 102b90c6cbeSBarry Smith 103b90c6cbeSBarry Smith /*@C 104811af0c4SBarry Smith PetscObjectSAWsSetBlock - Sets whether an object will block at `PetscObjectSAWsBlock()` 105b90c6cbeSBarry Smith 106c3339decSBarry Smith Collective 107b90c6cbeSBarry Smith 108b90c6cbeSBarry Smith Input Parameters: 109811af0c4SBarry Smith + obj - the PETSc variable 110b90c6cbeSBarry Smith - flg - whether it should block 111b90c6cbeSBarry Smith 112b90c6cbeSBarry Smith Level: advanced 113b90c6cbeSBarry Smith 114811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsBlock()`, `PetscSAWsBlock()` 115b90c6cbeSBarry Smith @*/ 116d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsSetBlock(PetscObject obj, PetscBool flg) 117d71ae5a4SJacob Faibussowitsch { 118b90c6cbeSBarry Smith PetscFunctionBegin; 119b90c6cbeSBarry Smith PetscValidHeader(obj, 1); 120b90c6cbeSBarry Smith obj->amspublishblock = flg; 1213ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 122b90c6cbeSBarry Smith } 123b90c6cbeSBarry Smith 124d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj) 125d71ae5a4SJacob Faibussowitsch { 1265f80ce2aSJacob Faibussowitsch char dir[PETSC_MAX_PATH_LEN]; 1279a492a5cSBarry Smith 12892e62aa6SBarry Smith PetscFunctionBegin; 1293ba16761SJacob Faibussowitsch if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(PETSC_SUCCESS); 1303ba16761SJacob Faibussowitsch if (!obj->amsmem) PetscFunctionReturn(PETSC_SUCCESS); 1319566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, sizeof(dir), "/PETSc/Objects/%s", obj->name)); 132792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, (dir)); 1333ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 13492e62aa6SBarry Smith } 135