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: if (da->ltog) {VecScatterDestroy(da->ltog);}
103: if (da->gtol) {VecScatterDestroy(da->gtol);}
104: if (da->ltol) {VecScatterDestroy(da->ltol);}
105: VecDestroy(da->global);
106: VecDestroy(da->local);
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: /*@C
142: DAGetISLocalToGlobalMapping - Accesses the local-to-global mapping in a DA.
144: Not Collective
146: Input Parameter:
147: . da - the distributed array that provides the mapping
149: Output Parameter:
150: . ltog - the mapping
152: Level: intermediate
154: Notes:
155: This mapping can them be used by VecSetLocalToGlobalMapping() or
156: MatSetLocalToGlobalMapping().
158: Essentially the same data is returned in the form of an integer array
159: with the routine DAGetGlobalIndices().
161: .keywords: distributed array, destroy
163: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
164: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
165: @*/
166: int DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
167: {
170: *map = da->ltogmap;
171: return(0);
172: }
174: /*@C
175: DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.
177: Not Collective
179: Input Parameter:
180: . da - the distributed array that provides the mapping
182: Output Parameter:
183: . ltog - the mapping
185: Level: intermediate
187: Notes:
188: This mapping can them be used by VecSetLocalToGlobalMappingBlock() or
189: MatSetLocalToGlobalMappingBlock().
191: Essentially the same data is returned in the form of an integer array
192: with the routine DAGetGlobalIndices().
194: .keywords: distributed array, destroy
196: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
197: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
198: @*/
199: int DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
200: {
203: *map = da->ltogmapb;
204: return(0);
205: }