Actual source code: pams.c

petsc-3.4.4 2014-03-13
  2: #include <petsc-private/petscimpl.h>        /*I    "petscsys.h"   I*/
  3: #include <petscviewerams.h>
  4: #include <petscsys.h>

  8: /*@C
  9:    PetscObjectAMSTakeAccess - Take access of the data fields that have been published to AMS 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(), PetscObjectAMSViewOff(), PetscObjectAMSGrantAccess()

 24: @*/
 25: PetscErrorCode  PetscObjectAMSTakeAccess(PetscObject obj)
 26: {
 28:   if (obj->amsmem != -1) {
 29:     PetscStackCallAMS(AMS_Memory_take_access,(obj->amsmem));
 30:   }
 31:   return(0);
 32: }

 36: /*@C
 37:    PetscObjectAMSGrantAccess - Grants access of the data fields that have been published to AMS 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(), PetscObjectAMSViewOff(), PetscObjectAMSTakeAccess()

 52: @*/
 53: PetscErrorCode  PetscObjectAMSGrantAccess(PetscObject obj)
 54: {
 56:   if (obj->amsmem != -1) {
 57:     PetscStackCallAMS(AMS_Memory_grant_access,(obj->amsmem));
 58:   }
 59:   return(0);
 60: }

 64: /*@C
 65:    PetscObjectAMSBlock - Blocks the object if PetscObjectAMSSetBlock() has been called

 67:    Collective on PetscObject

 69:    Input Parameters:
 70: .  obj - the Petsc variable
 71:          Thus must be cast with a (PetscObject), for example,
 72:          PetscObjectSetName((PetscObject)mat,name);


 75:    Level: advanced

 77:    Concepts: publishing object

 79: .seealso: PetscObjectSetName(), PetscObjectAMSViewOff(), PetscObjectAMSSetBlock()

 81: @*/
 82: PetscErrorCode  PetscObjectAMSBlock(PetscObject obj)
 83: {


 89:   if (!obj->amspublishblock) return(0);
 90:   PetscObjectAMSTakeAccess(obj);
 91:   while (obj->amsblock) {
 92:     PetscInfo(NULL,"Blocking on AMS\n");
 93:     PetscObjectAMSGrantAccess(obj);
 94:     PetscSleep(2.0);
 95:     PetscObjectAMSTakeAccess(obj);
 96:   }
 97:   PetscInfo(NULL,"Out of AMS block\n");
 98:   obj->amsblock = PETSC_TRUE;
 99:   PetscObjectAMSGrantAccess(obj);
100:   return(0);
101: }

105: /*@C
106:    PetscObjectAMSSetBlock - Sets whether an object will block at PetscObjectAMSBlock()

108:    Collective on PetscObject

110:    Input Parameters:
111: +  obj - the Petsc variable
112:          Thus must be cast with a (PetscObject), for example,
113:          PetscObjectSetName((PetscObject)mat,name);
114: -  flg - whether it should block

116:    Level: advanced

118:    Concepts: publishing object

120: .seealso: PetscObjectSetName(), PetscObjectAMSViewOff(), PetscObjectAMSBlock()

122: @*/
123: PetscErrorCode  PetscObjectAMSSetBlock(PetscObject obj,PetscBool flg)
124: {
127:   obj->amspublishblock = flg;
128:   obj->amsblock        = flg;
129:   return(0);
130: }

134: PetscErrorCode PetscObjectAMSViewOff(PetscObject obj)
135: {

139:   if (obj->classid == PETSC_VIEWER_CLASSID) return(0);
140:   if (obj->amsmem == -1) return(0);
141:   AMS_Memory_destroy(obj->amsmem);
142:   obj->amsmem = -1;
143:   return(0);
144: }