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: #undef __FUNCT__  
 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);}
137:   PetscHeaderDestroy(da);
138:   return(0);
139: }

141: #undef __FUNCT__  
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: #undef __FUNCT__  
178: /*@C
179:    DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.

181:    Not Collective

183:    Input Parameter:
184: .  da - the distributed array that provides the mapping 

186:    Output Parameter:
187: .  ltog - the mapping

189:    Level: intermediate

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

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

198: .keywords: distributed array, destroy

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