1b3506946SBarry Smith 2afcb2eb5SJed Brown #include <petsc-private/petscimpl.h> /*I "petscsys.h" I*/ 3ec7429eaSBarry Smith #include <petscviewerams.h> 4ec7429eaSBarry Smith #include <petscsys.h> 5b3506946SBarry Smith 6b3506946SBarry Smith #undef __FUNCT__ 7ec7429eaSBarry Smith #define __FUNCT__ "PetscObjectAMSTakeAccess" 8ec7429eaSBarry Smith /*@C 9ec7429eaSBarry Smith PetscObjectAMSTakeAccess - Take access of the data fields that have been published to AMS so they may be changed locally 10ec7429eaSBarry Smith 11ec7429eaSBarry Smith Collective on PetscObject 12ec7429eaSBarry Smith 13ec7429eaSBarry Smith Input Parameters: 14ec7429eaSBarry Smith . obj - the Petsc variable 15ec7429eaSBarry Smith Thus must be cast with a (PetscObject), for example, 16ec7429eaSBarry Smith PetscObjectSetName((PetscObject)mat,name); 17ec7429eaSBarry Smith 18ec7429eaSBarry Smith Level: advanced 19ec7429eaSBarry Smith 20ec7429eaSBarry Smith Concepts: publishing object 21ec7429eaSBarry Smith 22*f05ece33SBarry Smith .seealso: PetscObjectSetName(), PetscObjectAMSViewOff(), PetscObjectAMSGrantAccess() 23ec7429eaSBarry Smith 24ec7429eaSBarry Smith @*/ 25ec7429eaSBarry Smith PetscErrorCode PetscObjectAMSTakeAccess(PetscObject obj) 26ec7429eaSBarry Smith { 27ec7429eaSBarry Smith PetscFunctionBegin; 28ec7429eaSBarry Smith if (obj->amsmem != -1) { 29*f05ece33SBarry Smith PetscStackCallAMS(AMS_Memory_take_access,(obj->amsmem)); 30ec7429eaSBarry Smith } 31ec7429eaSBarry Smith PetscFunctionReturn(0); 32ec7429eaSBarry Smith } 33ec7429eaSBarry Smith 34ec7429eaSBarry Smith #undef __FUNCT__ 35ec7429eaSBarry Smith #define __FUNCT__ "PetscObjectAMSGrantAccess" 36ec7429eaSBarry Smith /*@C 37ec7429eaSBarry Smith PetscObjectAMSGrantAccess - Grants access of the data fields that have been published to AMS to the memory snooper to change 38ec7429eaSBarry Smith 39ec7429eaSBarry Smith Collective on PetscObject 40ec7429eaSBarry Smith 41ec7429eaSBarry Smith Input Parameters: 42ec7429eaSBarry Smith . obj - the Petsc variable 43ec7429eaSBarry Smith Thus must be cast with a (PetscObject), for example, 44ec7429eaSBarry Smith PetscObjectSetName((PetscObject)mat,name); 45ec7429eaSBarry Smith 46ec7429eaSBarry Smith Level: advanced 47ec7429eaSBarry Smith 48ec7429eaSBarry Smith Concepts: publishing object 49ec7429eaSBarry Smith 50*f05ece33SBarry Smith .seealso: PetscObjectSetName(), PetscObjectAMSViewOff(), PetscObjectAMSTakeAccess() 51ec7429eaSBarry Smith 52ec7429eaSBarry Smith @*/ 53ec7429eaSBarry Smith PetscErrorCode PetscObjectAMSGrantAccess(PetscObject obj) 54ec7429eaSBarry Smith { 55ec7429eaSBarry Smith PetscFunctionBegin; 56ec7429eaSBarry Smith if (obj->amsmem != -1) { 57*f05ece33SBarry Smith PetscStackCallAMS(AMS_Memory_grant_access,(obj->amsmem)); 58ec7429eaSBarry Smith } 59ec7429eaSBarry Smith PetscFunctionReturn(0); 60ec7429eaSBarry Smith } 61ec7429eaSBarry Smith 62ec7429eaSBarry Smith #undef __FUNCT__ 63b90c6cbeSBarry Smith #define __FUNCT__ "PetscObjectAMSBlock" 64b90c6cbeSBarry Smith /*@C 65b90c6cbeSBarry Smith PetscObjectAMSBlock - Blocks the object if PetscObjectAMSSetBlock() has been called 66b90c6cbeSBarry Smith 67b90c6cbeSBarry Smith Collective on PetscObject 68b90c6cbeSBarry Smith 69b90c6cbeSBarry Smith Input Parameters: 70b90c6cbeSBarry Smith . obj - the Petsc variable 71b90c6cbeSBarry Smith Thus must be cast with a (PetscObject), for example, 72b90c6cbeSBarry Smith PetscObjectSetName((PetscObject)mat,name); 73b90c6cbeSBarry Smith 74b90c6cbeSBarry Smith 75b90c6cbeSBarry Smith Level: advanced 76b90c6cbeSBarry Smith 77b90c6cbeSBarry Smith Concepts: publishing object 78b90c6cbeSBarry Smith 79*f05ece33SBarry Smith .seealso: PetscObjectSetName(), PetscObjectAMSViewOff(), PetscObjectAMSSetBlock() 80b90c6cbeSBarry Smith 81b90c6cbeSBarry Smith @*/ 82b90c6cbeSBarry Smith PetscErrorCode PetscObjectAMSBlock(PetscObject obj) 83b90c6cbeSBarry Smith { 84b90c6cbeSBarry Smith PetscFunctionBegin; 85b90c6cbeSBarry Smith PetscValidHeader(obj,1); 86b90c6cbeSBarry Smith 87b90c6cbeSBarry Smith if (!obj->amspublishblock) PetscFunctionReturn(0); 88b90c6cbeSBarry Smith /* Eventually this will be fixed to check if the AMS client has changed the lock */ 89b90c6cbeSBarry Smith while (1); 90b90c6cbeSBarry Smith PetscFunctionReturn(0); 91b90c6cbeSBarry Smith } 92b90c6cbeSBarry Smith 93b90c6cbeSBarry Smith #undef __FUNCT__ 94b90c6cbeSBarry Smith #define __FUNCT__ "PetscObjectAMSSetBlock" 95b90c6cbeSBarry Smith /*@C 96b90c6cbeSBarry Smith PetscObjectAMSSetBlock - Sets whether an object will block at PetscObjectAMSBlock() 97b90c6cbeSBarry Smith 98b90c6cbeSBarry Smith Collective on PetscObject 99b90c6cbeSBarry Smith 100b90c6cbeSBarry Smith Input Parameters: 101b90c6cbeSBarry Smith + obj - the Petsc variable 102b90c6cbeSBarry Smith Thus must be cast with a (PetscObject), for example, 103b90c6cbeSBarry Smith PetscObjectSetName((PetscObject)mat,name); 104b90c6cbeSBarry Smith - flg - whether it should block 105b90c6cbeSBarry Smith 106b90c6cbeSBarry Smith Level: advanced 107b90c6cbeSBarry Smith 108b90c6cbeSBarry Smith Concepts: publishing object 109b90c6cbeSBarry Smith 110*f05ece33SBarry Smith .seealso: PetscObjectSetName(), PetscObjectAMSViewOff(), PetscObjectAMSBlock() 111b90c6cbeSBarry Smith 112b90c6cbeSBarry Smith @*/ 113b90c6cbeSBarry Smith PetscErrorCode PetscObjectAMSSetBlock(PetscObject obj,PetscBool flg) 114b90c6cbeSBarry Smith { 115b90c6cbeSBarry Smith PetscFunctionBegin; 116b90c6cbeSBarry Smith PetscValidHeader(obj,1); 117b90c6cbeSBarry Smith obj->amspublishblock = flg; 118b90c6cbeSBarry Smith PetscFunctionReturn(0); 119b90c6cbeSBarry Smith } 120b90c6cbeSBarry Smith 121b90c6cbeSBarry Smith #undef __FUNCT__ 122*f05ece33SBarry Smith #define __FUNCT__ "PetscObjectAMSViewOff" 123*f05ece33SBarry Smith PetscErrorCode PetscObjectAMSViewOff(PetscObject obj) 12492e62aa6SBarry Smith { 12592e62aa6SBarry Smith PetscErrorCode ierr; 12692e62aa6SBarry Smith 12792e62aa6SBarry Smith PetscFunctionBegin; 1289fb22e1aSBarry Smith if (obj->classid == PETSC_VIEWER_CLASSID) PetscFunctionReturn(0); 129b90c6cbeSBarry Smith if (obj->amsmem == -1) PetscFunctionReturn(0); 130b90c6cbeSBarry Smith ierr = AMS_Memory_destroy(obj->amsmem);CHKERRQ(ierr); 131b90c6cbeSBarry Smith obj->amsmem = -1; 13292e62aa6SBarry Smith PetscFunctionReturn(0); 13392e62aa6SBarry Smith } 13492e62aa6SBarry Smith 135