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 PETSCDM_DLLEXPORT DA_COOKIE = 0;
11: PetscEvent DA_GlobalToLocal = 0, DA_LocalToGlobal = 0, DA_LocalADFunction = 0;
15: /*@
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: PetscErrorCode PETSCDM_DLLEXPORT DADestroy(DA da)
30: {
32: PetscErrorCode i,cnt = 0;
37: for (i=0; i<DA_MAX_WORK_VECTORS; i++) {
38: if (da->localin[i]) {cnt++;}
39: if (da->globalin[i]) {cnt++;}
40: }
42: if (--da->refct - cnt > 0) return(0);
43: /*
44: Need this test because the da references the vectors that
45: reference the da, so destroying the da calls destroy on the
46: vectors that cause another destroy on the da
47: */
48: if (da->refct < 0) return(0);
49: da->refct = 0;
51: for (i=0; i<DA_MAX_WORK_VECTORS; i++) {
52: if (da->localout[i]) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Destroying a DA that has a local vector obtained with DAGetLocalVector()");
53: if (da->localin[i]) {VecDestroy(da->localin[i]);}
54: if (da->globalout[i]) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Destroying a DA that has a global vector obtained with DAGetGlobalVector()");
55: if (da->globalin[i]) {VecDestroy(da->globalin[i]);}
56: }
58: for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
59: PetscFree(da->adstartghostedout[i]);
60: PetscFree(da->adstartghostedin[i]);
61: PetscFree(da->adstartout[i]);
62: PetscFree(da->adstartin[i]);
63: }
64: for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
65: PetscFree(da->admfstartghostedout[i]);
66: PetscFree(da->admfstartghostedin[i]);
67: PetscFree(da->admfstartout[i]);
68: PetscFree(da->admfstartin[i]);
69: }
70: for (i=0; i<DA_MAX_WORK_ARRAYS; i++) {
71: PetscFree(da->startghostedout[i]);
72: PetscFree(da->startghostedin[i]);
73: PetscFree(da->startout[i]);
74: PetscFree(da->startin[i]);
75: }
77: /* if memory was published with AMS then destroy it */
78: PetscObjectDepublish(da);
80: if (da->ltog) {VecScatterDestroy(da->ltog);}
81: if (da->gtol) {VecScatterDestroy(da->gtol);}
82: if (da->ltol) {VecScatterDestroy(da->ltol);}
83: if (da->natural){
84: VecDestroy(da->natural);
85: }
86: if (da->gton) {
87: VecScatterDestroy(da->gton);
88: }
90: if (da->ao) {
91: AODestroy(da->ao);
92: }
93: ISLocalToGlobalMappingDestroy(da->ltogmap);
94: ISLocalToGlobalMappingDestroy(da->ltogmapb);
96: PetscFree(da->lx);
97: PetscFree(da->ly);
98: PetscFree(da->lz);
100: for (i=0; i<da->w; i++) {
101: PetscStrfree(da->fieldname[i]);
102: }
103: PetscFree(da->fieldname);
105: if (da->localcoloring) {
106: ISColoringDestroy(da->localcoloring);
107: }
108: if (da->ghostedcoloring) {
109: ISColoringDestroy(da->ghostedcoloring);
110: }
112: if (da->coordinates) {VecDestroy(da->coordinates);}
113: if (da->ghosted_coordinates) {VecDestroy(da->ghosted_coordinates);}
114: if (da->da_coordinates && da != da->da_coordinates) {DADestroy(da->da_coordinates);}
116: PetscFree(da->dfill);
117: PetscFree(da->ofill);
118: PetscFree(da->e);
120: PetscHeaderDestroy(da);
121: return(0);
122: }
126: /*@
127: DAGetISLocalToGlobalMapping - Accesses the local-to-global mapping in a DA.
129: Not Collective
131: Input Parameter:
132: . da - the distributed array that provides the mapping
134: Output Parameter:
135: . ltog - the mapping
137: Level: intermediate
139: Notes:
140: This mapping can them be used by VecSetLocalToGlobalMapping() or
141: MatSetLocalToGlobalMapping().
143: Essentially the same data is returned in the form of an integer array
144: with the routine DAGetGlobalIndices().
146: .keywords: distributed array, destroy
148: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
149: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
150: @*/
151: PetscErrorCode PETSCDM_DLLEXPORT DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
152: {
156: *map = da->ltogmap;
157: return(0);
158: }
162: /*@
163: DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.
165: Not Collective
167: Input Parameter:
168: . da - the distributed array that provides the mapping
170: Output Parameter:
171: . ltog - the mapping
173: Level: intermediate
175: Notes:
176: This mapping can them be used by VecSetLocalToGlobalMappingBlock() or
177: MatSetLocalToGlobalMappingBlock().
179: Essentially the same data is returned in the form of an integer array
180: with the routine DAGetGlobalIndices().
182: .keywords: distributed array, destroy
184: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
185: MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
186: @*/
187: PetscErrorCode PETSCDM_DLLEXPORT DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
188: {
192: *map = da->ltogmapb;
193: return(0);
194: }