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;
 11: int DAEvents[DA_MAX_EVENTS];

 13: /*@C
 14:    DADestroy - Destroys a distributed array.

 16:    Collective on DA

 18:    Input Parameter:
 19: .  da - the distributed array to destroy 

 21:    Level: beginner

 23: .keywords: distributed array, destroy

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


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

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

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

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

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

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

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

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

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

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

137:   if (da->coordinates) {VecDestroy(da->coordinates);}
138:   if (da->gtog1) {PetscFree(da->gtog1);}
139:   PetscHeaderDestroy(da);
140:   return(0);
141: }

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

146:    Not Collective

148:    Input Parameter:
149: .  da - the distributed array that provides the mapping 

151:    Output Parameter:
152: .  ltog - the mapping

154:    Level: intermediate

156:    Notes:
157:    This mapping can them be used by VecSetLocalToGlobalMapping() or 
158:    MatSetLocalToGlobalMapping().

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

163: .keywords: distributed array, destroy

165: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
166:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
167: @*/
168: int DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
169: {
172:   *map = da->ltogmap;
173:   return(0);
174: }

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

179:    Not Collective

181:    Input Parameter:
182: .  da - the distributed array that provides the mapping 

184:    Output Parameter:
185: .  ltog - the mapping

187:    Level: intermediate

189:    Notes:
190:    This mapping can them be used by VecSetLocalToGlobalMappingBlock() or 
191:    MatSetLocalToGlobalMappingBlock().

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

196: .keywords: distributed array, destroy

198: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
199:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
200: @*/
201: int DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
202: {
205:   *map = da->ltogmapb;
206:   return(0);
207: }