Actual source code: dadestroy.c
1: #define PETSCDM_DLL
3: /*
4: Code for manipulating distributed regular arrays in parallel.
5: */
7: #include ../src/dm/da/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);
82: for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
83: PetscFree(da->adstartghostedout[i]);
84: PetscFree(da->adstartghostedin[i]);
85: PetscFree(da->adstartout[i]);
86: PetscFree(da->adstartin[i]);
87: }
88: for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
89: PetscFree(da->admfstartghostedout[i]);
90: PetscFree(da->admfstartghostedin[i]);
91: PetscFree(da->admfstartout[i]);
92: PetscFree(da->admfstartin[i]);
93: }
94: for (i=0; i<DA_MAX_WORK_ARRAYS; i++) {
95: PetscFree(da->startghostedout[i]);
96: PetscFree(da->startghostedin[i]);
97: PetscFree(da->startout[i]);
98: PetscFree(da->startin[i]);
99: }
101: /* if memory was published with AMS then destroy it */
102: PetscObjectDepublish(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: PetscFree(da->lx);
121: PetscFree(da->ly);
122: 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: if (da->ghosted_coordinates) {VecDestroy(da->ghosted_coordinates);}
138: if (da->da_coordinates && da != da->da_coordinates) {DADestroy(da->da_coordinates);}
140: PetscFree(da->neighbors);
141: PetscFree(da->dfill);
142: PetscFree(da->ofill);
143: PetscFree(da->e);
145: PetscHeaderDestroy(da);
146: return(0);
147: }
151: /*@
152: DAGetISLocalToGlobalMapping - Accesses the local-to-global mapping in a DA.
154: Not Collective
156: Input Parameter:
157: . da - the distributed array that provides the mapping
159: Output Parameter:
160: . ltog - the mapping
162: Level: intermediate
164: Notes:
165: This mapping can them be used by VecSetLocalToGlobalMapping() or
166: MatSetLocalToGlobalMapping().
168: Essentially the same data is returned in the form of an integer array
169: with the routine DAGetGlobalIndices().
171: .keywords: distributed array, destroy
173: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
174: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
175: @*/
176: PetscErrorCode DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
177: {
181: *map = da->ltogmap;
182: return(0);
183: }
187: /*@
188: DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.
190: Not Collective
192: Input Parameter:
193: . da - the distributed array that provides the mapping
195: Output Parameter:
196: . ltog - the mapping
198: Level: intermediate
200: Notes:
201: This mapping can them be used by VecSetLocalToGlobalMappingBlock() or
202: MatSetLocalToGlobalMappingBlock().
204: Essentially the same data is returned in the form of an integer array
205: with the routine DAGetGlobalIndices().
207: .keywords: distributed array, destroy
209: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
210: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
211: @*/
212: PetscErrorCode DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
213: {
217: *map = da->ltogmapb;
218: return(0);
219: }