Actual source code: dadestroy.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  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: PetscLogEvent DMDA_LocalADFunction;

 13: /*
 14:    DMDestroy_Private - handles the work vectors created by DMGetGlobalVector() and DMGetLocalVector()

 16: */
 17: PetscErrorCode  DMDestroy_Private(DM dm,PetscBool  *done)
 18: {
 20:   PetscErrorCode i,cnt = 0;

 24:   *done = PETSC_FALSE;

 26:   for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
 27:     if (dm->localin[i])  cnt++;
 28:     if (dm->globalin[i]) cnt++;
 29:   }

 31:   if (--((PetscObject)dm)->refct - cnt > 0) return(0);

 33:   /*
 34:          Need this test because the dm references the vectors that
 35:      reference the dm, so destroying the dm calls destroy on the
 36:      vectors that cause another destroy on the dm
 37:   */
 38:   if (((PetscObject)dm)->refct < 0) return(0);
 39:   ((PetscObject)dm)->refct = 0;

 41:   for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
 42:     if (dm->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()");
 43:     VecDestroy(&dm->localin[i]);
 44:     if (dm->globalout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a global vector obtained with DMGetGlobalVector()");
 45:     VecDestroy(&dm->globalin[i]);
 46:   }
 47:   ISLocalToGlobalMappingDestroy(&dm->ltogmap);

 49:   *done = PETSC_TRUE;
 50:   return(0);
 51: }

 55: PetscErrorCode  DMDestroy_DA(DM da)
 56: {
 58:   PetscErrorCode i;
 59:   DM_DA          *dd = (DM_DA*)da->data;

 62:   /* destroy the external/common part */
 63:   for (i=0; i<DMDA_MAX_WORK_ARRAYS; i++) {
 64:     PetscFree(dd->startghostedout[i]);
 65:     PetscFree(dd->startghostedin[i]);
 66:     PetscFree(dd->startout[i]);
 67:     PetscFree(dd->startin[i]);
 68:   }

 70:   VecScatterDestroy(&dd->gtol);
 71:   VecScatterDestroy(&dd->ltol);
 72:   VecDestroy(&dd->natural);
 73:   VecScatterDestroy(&dd->gton);
 74:   AODestroy(&dd->ao);
 75:   PetscFree(dd->aotype);

 77:   PetscFree(dd->lx);
 78:   PetscFree(dd->ly);
 79:   PetscFree(dd->lz);

 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);

102:   /* PetscSectionDestroy(&dd->defaultGlobalSection); */
103:   /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */
104:   PetscFree(dd);
105:   return(0);
106: }