Actual source code: dadestroy.c
petsc-3.9.4 2018-09-11
2: /*
3: Code for manipulating distributed regular arrays in parallel.
4: */
6: #include <petsc/private/dmdaimpl.h>
8: /* Logging support */
9: PetscLogEvent DMDA_LocalADFunction;
11: /*
12: DMDestroy_Private - handles the work vectors created by DMGetGlobalVector() and DMGetLocalVector()
14: */
15: PetscErrorCode DMDestroy_Private(DM dm,PetscBool *done)
16: {
18: PetscErrorCode i,cnt = 0;
22: *done = PETSC_FALSE;
24: for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
25: if (dm->localin[i]) cnt++;
26: if (dm->globalin[i]) cnt++;
27: }
29: if (--((PetscObject)dm)->refct - cnt > 0) return(0);
31: /*
32: Need this test because the dm references the vectors that
33: reference the dm, so destroying the dm calls destroy on the
34: vectors that cause another destroy on the dm
35: */
36: if (((PetscObject)dm)->refct < 0) return(0);
37: ((PetscObject)dm)->refct = 0;
39: for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
40: if (dm->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()");
41: VecDestroy(&dm->localin[i]);
42: if (dm->globalout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a global vector obtained with DMGetGlobalVector()");
43: VecDestroy(&dm->globalin[i]);
44: }
45: ISLocalToGlobalMappingDestroy(&dm->ltogmap);
47: *done = PETSC_TRUE;
48: return(0);
49: }
51: PetscErrorCode DMDestroy_DA(DM da)
52: {
54: PetscErrorCode i;
55: DM_DA *dd = (DM_DA*)da->data;
58: /* destroy the external/common part */
59: for (i=0; i<DMDA_MAX_WORK_ARRAYS; i++) {
60: PetscFree(dd->startghostedout[i]);
61: PetscFree(dd->startghostedin[i]);
62: PetscFree(dd->startout[i]);
63: PetscFree(dd->startin[i]);
64: }
66: VecScatterDestroy(&dd->gtol);
67: VecScatterDestroy(&dd->ltol);
68: VecDestroy(&dd->natural);
69: VecScatterDestroy(&dd->gton);
70: AODestroy(&dd->ao);
71: PetscFree(dd->aotype);
73: PetscFree(dd->lx);
74: PetscFree(dd->ly);
75: PetscFree(dd->lz);
77: PetscFree(dd->refine_x_hier);
78: PetscFree(dd->refine_y_hier);
79: PetscFree(dd->refine_z_hier);
81: if (dd->fieldname) {
82: for (i=0; i<dd->w; i++) {
83: PetscFree(dd->fieldname[i]);
84: }
85: PetscFree(dd->fieldname);
86: }
87: if (dd->coordinatename) {
88: for (i=0; i<da->dim; i++) {
89: PetscFree(dd->coordinatename[i]);
90: }
91: PetscFree(dd->coordinatename);
92: }
93: ISColoringDestroy(&dd->localcoloring);
94: ISColoringDestroy(&dd->ghostedcoloring);
96: PetscFree(dd->neighbors);
97: PetscFree(dd->dfill);
98: PetscFree(dd->ofill);
99: PetscFree(dd->ofillcols);
100: PetscFree(dd->e);
101: ISDestroy(&dd->ecorners);
103: PetscObjectComposeFunction((PetscObject)da,"DMSetUpGLVisViewer_C",NULL);
105: /* PetscSectionDestroy(&dd->defaultGlobalSection); */
106: /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */
107: PetscFree(dd);
108: return(0);
109: }