1af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 2e04113cfSBarry Smith #include <petscviewersaws.h> 3ec7429eaSBarry Smith #include <petscsys.h> 4b3506946SBarry Smith 5*ffeef943SBarry Smith /*@ 610450e9eSJacob Faibussowitsch PetscObjectSAWsTakeAccess - Take access of the data fields that have been published to SAWs 710450e9eSJacob Faibussowitsch by a `PetscObject` so their values may be changed in the computation 8ec7429eaSBarry Smith 9c3339decSBarry Smith Collective 10ec7429eaSBarry Smith 112fe279fdSBarry Smith Input Parameter: 12811af0c4SBarry Smith . obj - the `PetscObject` variable. This must be cast with a (`PetscObject`), for example, `PetscObjectSAWSTakeAccess`((`PetscObject`)mat); 13ec7429eaSBarry Smith 14ec7429eaSBarry Smith Level: advanced 15ec7429eaSBarry Smith 1610450e9eSJacob Faibussowitsch Developer Notes: 1710450e9eSJacob Faibussowitsch The naming should perhaps be changed to `PetscObjectSAWsGetAccess()` and 1810450e9eSJacob Faibussowitsch `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 31*ffeef943SBarry Smith /*@ 3210450e9eSJacob Faibussowitsch PetscObjectSAWsGrantAccess - Grants access of the data fields that have been published to 3310450e9eSJacob Faibussowitsch SAWs called when the changes made during `PetscObjectSAWsTakeAccess()` are complete. 34ec7429eaSBarry Smith 35c3339decSBarry Smith Collective 36ec7429eaSBarry Smith 372fe279fdSBarry 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 4210450e9eSJacob Faibussowitsch Notes: 4310450e9eSJacob Faibussowitsch This allows the webserve to change the published values. 4410450e9eSJacob Faibussowitsch 45db781477SPatrick Sanan .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsTakeAccess()` 46ec7429eaSBarry Smith @*/ 47d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject obj) 48d71ae5a4SJacob Faibussowitsch { 49ec957eceSBarry Smith if (obj->amsmem) { 5016ad0300SBarry Smith /* cannot wrap with PetscPushStack() because that also deals with the locks */ 519a492a5cSBarry Smith SAWs_Unlock(); 52ec7429eaSBarry Smith } 533ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 54ec7429eaSBarry Smith } 55ec7429eaSBarry Smith 567aab2a10SBarry Smith /*@C 57811af0c4SBarry Smith PetscSAWsBlock - Blocks on SAWs until a client (person using the web browser) unblocks it 587aab2a10SBarry Smith 597aab2a10SBarry Smith Not Collective 607aab2a10SBarry Smith 617aab2a10SBarry Smith Level: advanced 627aab2a10SBarry Smith 63db781477SPatrick Sanan .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsSetBlock()`, `PetscObjectSAWsBlock()` 647aab2a10SBarry Smith @*/ 65d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSAWsBlock(void) 66d71ae5a4SJacob Faibussowitsch { 677aab2a10SBarry Smith volatile PetscBool block = PETSC_TRUE; 687aab2a10SBarry Smith 697aab2a10SBarry Smith PetscFunctionBegin; 70792fecdfSBarry Smith PetscCallSAWs(SAWs_Register, ("__Block", (PetscBool *)&block, 1, SAWs_WRITE, SAWs_BOOLEAN)); 717aab2a10SBarry Smith SAWs_Lock(); 727aab2a10SBarry Smith while (block) { 737aab2a10SBarry Smith SAWs_Unlock(); 749566063dSJacob Faibussowitsch PetscCall(PetscInfo(NULL, "Blocking on SAWs\n")); 759566063dSJacob Faibussowitsch PetscCall(PetscSleep(.3)); 767aab2a10SBarry Smith SAWs_Lock(); 777aab2a10SBarry Smith } 787aab2a10SBarry Smith SAWs_Unlock(); 79792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, ("__Block")); 809566063dSJacob Faibussowitsch PetscCall(PetscInfo(NULL, "Out of SAWs block\n")); 813ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 827aab2a10SBarry Smith } 837aab2a10SBarry Smith 84*ffeef943SBarry Smith /*@ 85811af0c4SBarry Smith PetscObjectSAWsBlock - Blocks the object if `PetscObjectSAWsSetBlock()` has been called 86b90c6cbeSBarry Smith 87c3339decSBarry Smith Collective 88b90c6cbeSBarry Smith 892fe279fdSBarry Smith Input Parameter: 90811af0c4SBarry Smith . obj - the PETSc variable 91b90c6cbeSBarry Smith 92b90c6cbeSBarry Smith Level: advanced 93b90c6cbeSBarry Smith 94811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsSetBlock()`, `PetscSAWsBlock()` 95b90c6cbeSBarry Smith @*/ 96d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsBlock(PetscObject obj) 97d71ae5a4SJacob Faibussowitsch { 98b90c6cbeSBarry Smith PetscFunctionBegin; 99b90c6cbeSBarry Smith PetscValidHeader(obj, 1); 100b90c6cbeSBarry Smith 1013ba16761SJacob Faibussowitsch if (!obj->amspublishblock || !obj->amsmem) PetscFunctionReturn(PETSC_SUCCESS); 1029566063dSJacob Faibussowitsch PetscCall(PetscSAWsBlock()); 1033ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 104b90c6cbeSBarry Smith } 105b90c6cbeSBarry Smith 106*ffeef943SBarry Smith /*@ 107811af0c4SBarry Smith PetscObjectSAWsSetBlock - Sets whether an object will block at `PetscObjectSAWsBlock()` 108b90c6cbeSBarry Smith 109c3339decSBarry Smith Collective 110b90c6cbeSBarry Smith 111b90c6cbeSBarry Smith Input Parameters: 112811af0c4SBarry Smith + obj - the PETSc variable 113b90c6cbeSBarry Smith - flg - whether it should block 114b90c6cbeSBarry Smith 115b90c6cbeSBarry Smith Level: advanced 116b90c6cbeSBarry Smith 117811af0c4SBarry Smith .seealso: `PetscObjectSetName()`, `PetscObjectSAWsViewOff()`, `PetscObjectSAWsBlock()`, `PetscSAWsBlock()` 118b90c6cbeSBarry Smith @*/ 119d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsSetBlock(PetscObject obj, PetscBool flg) 120d71ae5a4SJacob Faibussowitsch { 121b90c6cbeSBarry Smith PetscFunctionBegin; 122b90c6cbeSBarry Smith PetscValidHeader(obj, 1); 123b90c6cbeSBarry Smith obj->amspublishblock = flg; 1243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 125b90c6cbeSBarry Smith } 126b90c6cbeSBarry Smith 127d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSAWsViewOff(PetscObject obj) 128d71ae5a4SJacob Faibussowitsch { 1295f80ce2aSJacob Faibussowitsch char dir[PETSC_MAX_PATH_LEN]; 1309a492a5cSBarry Smith 13192e62aa6SBarry Smith PetscFunctionBegin; 1323ba16761SJacob Faibussowitsch if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(PETSC_SUCCESS); 1333ba16761SJacob Faibussowitsch if (!obj->amsmem) PetscFunctionReturn(PETSC_SUCCESS); 1349566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(dir, sizeof(dir), "/PETSc/Objects/%s", obj->name)); 135792fecdfSBarry Smith PetscCallSAWs(SAWs_Delete, (dir)); 1363ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 13792e62aa6SBarry Smith } 138