2: /* 3: Code for manipulating distributed regular arrays in parallel. 4: */ 6: #include <petsc-private/dmdaimpl.h> /*I "petscdmda.h" I*/ 8: /* Logging support */ 9: PetscClassId ADDA_CLASSID; 10: PetscLogEvent DMDA_LocalADFunction; 14: /* 15: DMDestroy_Private - handles the work vectors created by DMGetGlobalVector() and DMGetLocalVector() 17: */ 18: PetscErrorCode DMDestroy_Private(DM dm,PetscBool *done) 19: { 21: PetscErrorCode i,cnt = 0; 25: *done = PETSC_FALSE; 27: for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 28: if (dm->localin[i]) cnt++; 29: if (dm->globalin[i]) cnt++; 30: } 32: if (--((PetscObject)dm)->refct - cnt > 0) return(0); 34: /* 35: Need this test because the dm references the vectors that 36: reference the dm, so destroying the dm calls destroy on the 37: vectors that cause another destroy on the dm 38: */ 39: if (((PetscObject)dm)->refct < 0) return(0); 40: ((PetscObject)dm)->refct = 0; 42: for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 43: if (dm->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 44: VecDestroy(&dm->localin[i]); 45: if (dm->globalout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a global vector obtained with DMGetGlobalVector()"); 46: VecDestroy(&dm->globalin[i]); 47: } 48: ISLocalToGlobalMappingDestroy(&dm->ltogmap); 49: ISLocalToGlobalMappingDestroy(&dm->ltogmapb); 51: *done = PETSC_TRUE; 52: return(0); 53: } 57: PetscErrorCode DMDestroy_DA(DM da) 58: { 60: PetscErrorCode i; 61: DM_DA *dd = (DM_DA*)da->data; 64: /* destroy the external/common part */ 65: for (i=0; i<DMDA_MAX_WORK_ARRAYS; i++) { 66: PetscFree(dd->startghostedout[i]); 67: PetscFree(dd->startghostedin[i]); 68: PetscFree(dd->startout[i]); 69: PetscFree(dd->startin[i]); 70: } 72: VecScatterDestroy(&dd->ltog); 73: VecScatterDestroy(&dd->gtol); 74: VecScatterDestroy(&dd->ltol); 75: VecDestroy(&dd->natural); 76: VecScatterDestroy(&dd->gton); 77: AODestroy(&dd->ao); 79: PetscFree(dd->idx); 80: PetscFree(dd->lx); 81: PetscFree(dd->ly); 82: PetscFree(dd->lz); 84: if (dd->fieldname) { 85: for (i=0; i<dd->w; i++) { 86: PetscFree(dd->fieldname[i]); 87: } 88: PetscFree(dd->fieldname); 89: } 90: if (dd->coordinatename) { 91: for (i=0; i<dd->dim; i++) { 92: PetscFree(dd->coordinatename[i]); 93: } 94: PetscFree(dd->coordinatename); 95: } 96: ISColoringDestroy(&dd->localcoloring); 97: ISColoringDestroy(&dd->ghostedcoloring); 99: PetscFree(dd->neighbors); 100: PetscFree(dd->dfill); 101: PetscFree(dd->ofill); 102: PetscFree(dd->ofillcols); 103: PetscFree(dd->e); 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: }