Actual source code: dadestroy.c

  1: /*$Id: dadestroy.c,v 1.44 2001/06/21 21:19:09 bsmith Exp $*/
  2: 
  3: /*
  4:   Code for manipulating distributed regular arrays in parallel.
  5: */

 7:  #include src/dm/da/daimpl.h

  9: /* Logging support */
 10: int DA_COOKIE = 0;
 11: int DAEvents[DA_MAX_EVENTS] = {0};

 15: /*@C
 16:    DADestroy - Destroys a distributed array.

 18:    Collective on DA

 20:    Input Parameter:
 21: .  da - the distributed array to destroy 

 23:    Level: beginner

 25: .keywords: distributed array, destroy

 27: .seealso: DACreate1d(), DACreate2d(), DACreate3d()
 28: @*/
 29: int DADestroy(DA da)
 30: {
 31:   int ierr,i,cnt = 0;


 36:   for (i=0; i<DA_MAX_WORK_VECTORS; i++) {
 37:     if (da->localin[i])  {cnt++;}
 38:     if (da->globalin[i]) {cnt++;}
 39:   }

 41:   if (--da->refct - cnt > 0) return(0);
 42:   /*
 43:          Need this test because the da references the vectors that 
 44:      reference the da, so destroying the da calls destroy on the 
 45:      vectors that cause another destroy on the da
 46:   */
 47:   if (da->refct < 0) return(0);
 48:   da->refct = 0;

 50:   for (i=0; i<DA_MAX_WORK_VECTORS; i++) {
 51:     if (da->localout[i]) SETERRQ(1,"Destroying a DA that has a local vector obtained with DAGetLocalVector()");
 52:     if (da->localin[i]) {VecDestroy(da->localin[i]);}
 53:     if (da->globalout[i]) SETERRQ(1,"Destroying a DA that has a global vector obtained with DAGetGlobalVector()");
 54:     if (da->globalin[i]) {VecDestroy(da->globalin[i]);}
 55:   }

 57:   for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
 58:     if (da->adstartghostedout[i]){
 59:       PetscFree(da->adstartghostedout[i]);
 60:     }
 61:     if (da->adstartghostedin[i]){
 62:       PetscFree(da->adstartghostedin[i]);
 63:     }
 64:     if (da->adstartout[i]){
 65:       PetscFree(da->adstartout[i]);
 66:     }
 67:     if (da->adstartin[i]){
 68:       PetscFree(da->adstartin[i]);
 69:     }
 70:   }
 71:   for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
 72:     if (da->admfstartghostedout[i]){
 73:       PetscFree(da->admfstartghostedout[i]);
 74:     }
 75:     if (da->admfstartghostedin[i]){
 76:       PetscFree(da->admfstartghostedin[i]);
 77:     }
 78:     if (da->admfstartout[i]){
 79:       PetscFree(da->admfstartout[i]);
 80:     }
 81:     if (da->admfstartin[i]){
 82:       PetscFree(da->admfstartin[i]);
 83:     }
 84:   }
 85:   for (i=0; i<DA_MAX_WORK_ARRAYS; i++) {
 86:     if (da->startghostedout[i]){
 87:       PetscFree(da->startghostedout[i]);
 88:     }
 89:     if (da->startghostedin[i]){
 90:       PetscFree(da->startghostedin[i]);
 91:     }
 92:     if (da->startout[i]){
 93:       PetscFree(da->startout[i]);
 94:     }
 95:     if (da->startin[i]){
 96:       PetscFree(da->startin[i]);
 97:     }
 98:   }

100:   /* if memory was published with AMS then destroy it */
101:   PetscObjectDepublish(da);

103:   PetscLogObjectDestroy(da);
104:   if (da->ltog)   {VecScatterDestroy(da->ltog);}
105:   if (da->gtol)   {VecScatterDestroy(da->gtol);}
106:   if (da->ltol)   {VecScatterDestroy(da->ltol);}
107:   if (da->natural){
108:     VecDestroy(da->natural);
109:   }
110:   if (da->gton) {
111:     VecScatterDestroy(da->gton);
112:   }

114:   if (da->ao) {
115:     AODestroy(da->ao);
116:   }
117:   ISLocalToGlobalMappingDestroy(da->ltogmap);
118:   ISLocalToGlobalMappingDestroy(da->ltogmapb);

120:   if (da->lx) {PetscFree(da->lx);}
121:   if (da->ly) {PetscFree(da->ly);}
122:   if (da->lz) {PetscFree(da->lz);}

124:   for (i=0; i<da->w; i++) {
125:     PetscStrfree(da->fieldname[i]);
126:   }
127:   PetscFree(da->fieldname);

129:   if (da->localcoloring) {
130:     ISColoringDestroy(da->localcoloring);
131:   }
132:   if (da->ghostedcoloring) {
133:     ISColoringDestroy(da->ghostedcoloring);
134:   }

136:   if (da->coordinates) {VecDestroy(da->coordinates);}

138:   if (da->dfill) {PetscFree(da->dfill);}
139:   if (da->ofill) {PetscFree(da->ofill);
140:   }

142:   PetscHeaderDestroy(da);
143:   return(0);
144: }

148: /*@C
149:    DAGetISLocalToGlobalMapping - Accesses the local-to-global mapping in a DA.

151:    Not Collective

153:    Input Parameter:
154: .  da - the distributed array that provides the mapping 

156:    Output Parameter:
157: .  ltog - the mapping

159:    Level: intermediate

161:    Notes:
162:    This mapping can them be used by VecSetLocalToGlobalMapping() or 
163:    MatSetLocalToGlobalMapping().

165:    Essentially the same data is returned in the form of an integer array
166:    with the routine DAGetGlobalIndices().

168: .keywords: distributed array, destroy

170: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
171:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
172: @*/
173: int DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
174: {
178:   *map = da->ltogmap;
179:   return(0);
180: }

184: /*@C
185:    DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.

187:    Not Collective

189:    Input Parameter:
190: .  da - the distributed array that provides the mapping 

192:    Output Parameter:
193: .  ltog - the mapping

195:    Level: intermediate

197:    Notes:
198:    This mapping can them be used by VecSetLocalToGlobalMappingBlock() or 
199:    MatSetLocalToGlobalMappingBlock().

201:    Essentially the same data is returned in the form of an integer array
202:    with the routine DAGetGlobalIndices().

204: .keywords: distributed array, destroy

206: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
207:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
208: @*/
209: int DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
210: {
214:   *map = da->ltogmapb;
215:   return(0);
216: }