Actual source code: dadestroy.c

petsc-3.11.4 2019-09-28
Report Typos and Errors

  2: /*
  3:   Code for manipulating distributed regular arrays in parallel.
  4: */

  6:  #include <petsc/private/dmdaimpl.h>

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

 11: */
 12: PetscErrorCode  DMDestroy_Private(DM dm,PetscBool  *done)
 13: {
 15:   PetscErrorCode i,cnt = 0;

 19:   *done = PETSC_FALSE;

 21:   for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
 22:     if (dm->localin[i])  cnt++;
 23:     if (dm->globalin[i]) cnt++;
 24:   }

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

 28:   /*
 29:          Need this test because the dm references the vectors that
 30:      reference the dm, so destroying the dm calls destroy on the
 31:      vectors that cause another destroy on the dm
 32:   */
 33:   if (((PetscObject)dm)->refct < 0) return(0);
 34:   ((PetscObject)dm)->refct = 0;

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

 44:   *done = PETSC_TRUE;
 45:   return(0);
 46: }

 48: PetscErrorCode  DMDestroy_DA(DM da)
 49: {
 51:   PetscErrorCode i;
 52:   DM_DA          *dd = (DM_DA*)da->data;

 55:   /* destroy the external/common part */
 56:   for (i=0; i<DMDA_MAX_WORK_ARRAYS; i++) {
 57:     PetscFree(dd->startghostedout[i]);
 58:     PetscFree(dd->startghostedin[i]);
 59:     PetscFree(dd->startout[i]);
 60:     PetscFree(dd->startin[i]);
 61:   }

 63:   VecScatterDestroy(&dd->gtol);
 64:   VecScatterDestroy(&dd->ltol);
 65:   VecDestroy(&dd->natural);
 66:   VecScatterDestroy(&dd->gton);
 67:   AODestroy(&dd->ao);
 68:   PetscFree(dd->aotype);

 70:   PetscFree(dd->lx);
 71:   PetscFree(dd->ly);
 72:   PetscFree(dd->lz);

 74:   PetscFree(dd->refine_x_hier);
 75:   PetscFree(dd->refine_y_hier);
 76:   PetscFree(dd->refine_z_hier);

 78:   if (dd->fieldname) {
 79:     for (i=0; i<dd->w; i++) {
 80:       PetscFree(dd->fieldname[i]);
 81:     }
 82:     PetscFree(dd->fieldname);
 83:   }
 84:   if (dd->coordinatename) {
 85:     for (i=0; i<da->dim; i++) {
 86:       PetscFree(dd->coordinatename[i]);
 87:     }
 88:     PetscFree(dd->coordinatename);
 89:   }
 90:   ISColoringDestroy(&dd->localcoloring);
 91:   ISColoringDestroy(&dd->ghostedcoloring);

 93:   PetscFree(dd->neighbors);
 94:   PetscFree(dd->dfill);
 95:   PetscFree(dd->ofill);
 96:   PetscFree(dd->ofillcols);
 97:   PetscFree(dd->e);
 98:   ISDestroy(&dd->ecorners);

100:   PetscObjectComposeFunction((PetscObject)da,"DMSetUpGLVisViewer_C",NULL);

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: }