Actual source code: dadestroy.c

  1: /*$Id: dadestroy.c,v 1.43 2001/03/23 23:25:00 balay Exp $*/
  2: 
  3: /*
  4:   Code for manipulating distributed regular arrays in parallel.
  5: */

  7: #include "src/dm/da/daimpl.h"    /*I   "petscda.h"   I*/

  9: /*@C
 10:    DADestroy - Destroys a distributed array.

 12:    Collective on DA

 14:    Input Parameter:
 15: .  da - the distributed array to destroy 

 17:    Level: beginner

 19: .keywords: distributed array, destroy

 21: .seealso: DACreate1d(), DACreate2d(), DACreate3d()
 22: @*/
 23: int DADestroy(DA da)
 24: {
 25:   int ierr,i,cnt = 0;


 30:   for (i=0; i<10; i++) {
 31:     if (da->localin[i])  {cnt++;}
 32:     if (da->globalin[i]) {cnt++;}
 33:   }

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

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

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

 54:   PetscLogObjectDestroy(da);
 55:   PetscFree(da->idx);
 56:   VecScatterDestroy(da->ltog);
 57:   VecScatterDestroy(da->gtol);
 58:   VecScatterDestroy(da->ltol);
 59:   VecDestroy(da->global);
 60:   VecDestroy(da->local);
 61:   if (da->natural){
 62:     VecDestroy(da->natural);
 63:   }
 64:   if (da->gton) {
 65:     VecScatterDestroy(da->gton);
 66:   }

 68:   if (da->ao) {
 69:     AODestroy(da->ao);
 70:   }
 71:   ISLocalToGlobalMappingDestroy(da->ltogmap);
 72:   ISLocalToGlobalMappingDestroy(da->ltogmapb);

 74:   if (da->lx) {PetscFree(da->lx);}
 75:   if (da->ly) {PetscFree(da->ly);}
 76:   if (da->lz) {PetscFree(da->lz);}

 78:   for (i=0; i<da->w; i++) {
 79:     PetscStrfree(da->fieldname[i]);
 80:   }
 81:   PetscFree(da->fieldname);

 83:   if (da->coordinates) {VecDestroy(da->coordinates);}
 84:   if (da->gtog1) {PetscFree(da->gtog1);}
 85:   PetscHeaderDestroy(da);
 86:   return(0);
 87: }

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

 92:    Not Collective

 94:    Input Parameter:
 95: .  da - the distributed array that provides the mapping 

 97:    Output Parameter:
 98: .  ltog - the mapping

100:    Level: intermediate

102:    Notes:
103:    This mapping can them be used by VecSetLocalToGlobalMapping() or 
104:    MatSetLocalToGlobalMapping().

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

109: .keywords: distributed array, destroy

111: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
112:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
113: @*/
114: int DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
115: {
118:   *map = da->ltogmap;
119:   return(0);
120: }

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

125:    Not Collective

127:    Input Parameter:
128: .  da - the distributed array that provides the mapping 

130:    Output Parameter:
131: .  ltog - the mapping

133:    Level: intermediate

135:    Notes:
136:    This mapping can them be used by VecSetLocalToGlobalMappingBlock() or 
137:    MatSetLocalToGlobalMappingBlock().

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

142: .keywords: distributed array, destroy

144: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
145:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
146: @*/
147: int DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
148: {
151:   *map = da->ltogmapb;
152:   return(0);
153: }