Actual source code: dadestroy.c
1: #define PETSCDM_DLL
3: /*
4: Code for manipulating distributed regular arrays in parallel.
5: */
7: #include private/daimpl.h
9: /* Logging support */
10: PetscCookie DM_COOKIE;
11: PetscCookie ADDA_COOKIE;
12: PetscLogEvent DA_GlobalToLocal, DA_LocalToGlobal, DA_LocalADFunction;
16: /*
17: DMDestroy_Private - handles the work vectors created by DMGetGlobalVector() and DMGetLocalVector()
19: */
20: PetscErrorCode DMDestroy_Private(DM dm,PetscTruth *done)
21: {
23: PetscErrorCode i,cnt = 0;
27: *done = PETSC_FALSE;
29: for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
30: if (dm->localin[i]) {cnt++;}
31: if (dm->globalin[i]) {cnt++;}
32: }
34: if (--((PetscObject)dm)->refct - cnt > 0) return(0);
36: /*
37: Need this test because the dm references the vectors that
38: reference the dm, so destroying the dm calls destroy on the
39: vectors that cause another destroy on the dm
40: */
41: if (((PetscObject)dm)->refct < 0) return(0);
42: ((PetscObject)dm)->refct = 0;
44: for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
45: if (dm->localout[i]) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()");
46: if (dm->localin[i]) {VecDestroy(dm->localin[i]);}
47: if (dm->globalout[i]) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a global vector obtained with DMGetGlobalVector()");
48: if (dm->globalin[i]) {VecDestroy(dm->globalin[i]);}
49: }
50: *done = PETSC_TRUE;
51: return(0);
52: }
56: /*@
57: DADestroy - Destroys a distributed array.
59: Collective on DA
61: Input Parameter:
62: . da - the distributed array to destroy
64: Level: beginner
66: .keywords: distributed array, destroy
68: .seealso: DACreate1d(), DACreate2d(), DACreate3d()
69: @*/
70: PetscErrorCode DADestroy(DA da)
71: {
73: PetscErrorCode i;
74: PetscTruth done;
79: DMDestroy_Private((DM)da,&done);
80: if (!done) return(0);
81: /* destroy the internal part */
82: if (da->ops->destroy) {
83: (*da->ops->destroy)(da);
84: }
85: /* destroy the external/common part */
86: for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
87: PetscFree(da->adstartghostedout[i]);
88: PetscFree(da->adstartghostedin[i]);
89: PetscFree(da->adstartout[i]);
90: PetscFree(da->adstartin[i]);
91: }
92: for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
93: PetscFree(da->admfstartghostedout[i]);
94: PetscFree(da->admfstartghostedin[i]);
95: PetscFree(da->admfstartout[i]);
96: PetscFree(da->admfstartin[i]);
97: }
98: for (i=0; i<DA_MAX_WORK_ARRAYS; i++) {
99: PetscFree(da->startghostedout[i]);
100: PetscFree(da->startghostedin[i]);
101: PetscFree(da->startout[i]);
102: PetscFree(da->startin[i]);
103: }
105: /* if memory was published with AMS then destroy it */
106: PetscObjectDepublish(da);
108: if (da->ltog) {VecScatterDestroy(da->ltog);}
109: if (da->gtol) {VecScatterDestroy(da->gtol);}
110: if (da->ltol) {VecScatterDestroy(da->ltol);}
111: if (da->natural){
112: VecDestroy(da->natural);
113: }
114: if (da->gton) {
115: VecScatterDestroy(da->gton);
116: }
118: if (da->ao) {
119: AODestroy(da->ao);
120: }
121: if (da->ltogmap) {
122: ISLocalToGlobalMappingDestroy(da->ltogmap);
123: }
124: if (da->ltogmapb) {
125: ISLocalToGlobalMappingDestroy(da->ltogmapb);
126: }
128: PetscFree(da->lx);
129: PetscFree(da->ly);
130: PetscFree(da->lz);
132: if (da->fieldname) {
133: for (i=0; i<da->w; i++) {
134: PetscStrfree(da->fieldname[i]);
135: }
136: PetscFree(da->fieldname);
137: }
139: if (da->localcoloring) {
140: ISColoringDestroy(da->localcoloring);
141: }
142: if (da->ghostedcoloring) {
143: ISColoringDestroy(da->ghostedcoloring);
144: }
146: if (da->coordinates) {VecDestroy(da->coordinates);}
147: if (da->ghosted_coordinates) {VecDestroy(da->ghosted_coordinates);}
148: if (da->da_coordinates && da != da->da_coordinates) {DADestroy(da->da_coordinates);}
150: PetscFree(da->neighbors);
151: PetscFree(da->dfill);
152: PetscFree(da->ofill);
153: PetscFree(da->e);
155: PetscHeaderDestroy(da);
156: return(0);
157: }
161: /*@
162: DAGetISLocalToGlobalMapping - Accesses the local-to-global mapping in a DA.
164: Not Collective
166: Input Parameter:
167: . da - the distributed array that provides the mapping
169: Output Parameter:
170: . ltog - the mapping
172: Level: intermediate
174: Notes:
175: This mapping can them be used by VecSetLocalToGlobalMapping() or
176: MatSetLocalToGlobalMapping().
178: Essentially the same data is returned in the form of an integer array
179: with the routine DAGetGlobalIndices().
181: .keywords: distributed array, destroy
183: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
184: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
185: @*/
186: PetscErrorCode DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
187: {
191: *map = da->ltogmap;
192: return(0);
193: }
197: /*@
198: DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.
200: Not Collective
202: Input Parameter:
203: . da - the distributed array that provides the mapping
205: Output Parameter:
206: . ltog - the mapping
208: Level: intermediate
210: Notes:
211: This mapping can them be used by VecSetLocalToGlobalMappingBlock() or
212: MatSetLocalToGlobalMappingBlock().
214: Essentially the same data is returned in the form of an integer array
215: with the routine DAGetGlobalIndices().
217: .keywords: distributed array, destroy
219: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
220: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
221: @*/
222: PetscErrorCode DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
223: {
227: *map = da->ltogmapb;
228: return(0);
229: }