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: /*@C
     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:     if (da->adstartghostedout[i]){
     60:       PetscFree(da->adstartghostedout[i]);
     61:     }
     62:     if (da->adstartghostedin[i]){
     63:       PetscFree(da->adstartghostedin[i]);
     64:     }
     65:     if (da->adstartout[i]){
     66:       PetscFree(da->adstartout[i]);
     67:     }
     68:     if (da->adstartin[i]){
     69:       PetscFree(da->adstartin[i]);
     70:     }
     71:   }
     72:   for (i=0; i<DA_MAX_AD_ARRAYS; i++) {
     73:     if (da->admfstartghostedout[i]){
     74:       PetscFree(da->admfstartghostedout[i]);
     75:     }
     76:     if (da->admfstartghostedin[i]){
     77:       PetscFree(da->admfstartghostedin[i]);
     78:     }
     79:     if (da->admfstartout[i]){
     80:       PetscFree(da->admfstartout[i]);
     81:     }
     82:     if (da->admfstartin[i]){
     83:       PetscFree(da->admfstartin[i]);
     84:     }
     85:   }
     86:   for (i=0; i<DA_MAX_WORK_ARRAYS; i++) {
     87:     if (da->startghostedout[i]){
     88:       PetscFree(da->startghostedout[i]);
     89:     }
     90:     if (da->startghostedin[i]){
     91:       PetscFree(da->startghostedin[i]);
     92:     }
     93:     if (da->startout[i]){
     94:       PetscFree(da->startout[i]);
     95:     }
     96:     if (da->startin[i]){
     97:       PetscFree(da->startin[i]);
     98:     }
     99:   }

    101:   /* if memory was published with AMS then destroy it */
    102:   PetscObjectDepublish(da);

    104:   if (da->ltog)   {VecScatterDestroy(da->ltog);}
    105:   if (da->gtol)   {VecScatterDestroy(da->gtol);}
    106:   if (da->ltol)   {VecScatterDestroy(da->ltol);}
    107:   if (da->natural){
    108:     VecDestroy(da->natural);
    109:   }
    110:   if (da->gton) {
    111:     VecScatterDestroy(da->gton);
    112:   }

    114:   if (da->ao) {
    115:     AODestroy(da->ao);
    116:   }
    117:   ISLocalToGlobalMappingDestroy(da->ltogmap);
    118:   ISLocalToGlobalMappingDestroy(da->ltogmapb);

    120:   if (da->lx) {PetscFree(da->lx);}
    121:   if (da->ly) {PetscFree(da->ly);}
    122:   if (da->lz) {PetscFree(da->lz);}

    124:   for (i=0; i<da->w; i++) {
    125:     PetscStrfree(da->fieldname[i]);
    126:   }
    127:   PetscFree(da->fieldname);

    129:   if (da->localcoloring) {
    130:     ISColoringDestroy(da->localcoloring);
    131:   }
    132:   if (da->ghostedcoloring) {
    133:     ISColoringDestroy(da->ghostedcoloring);
    134:   }

    136:   if (da->coordinates) {VecDestroy(da->coordinates);}
    137:   if (da->ghosted_coordinates) {VecDestroy(da->ghosted_coordinates);}
    138:   if (da->da_coordinates && da != da->da_coordinates) {DADestroy(da->da_coordinates);}

    140:   if (da->dfill) {PetscFree(da->dfill);}
    141:   if (da->ofill) {PetscFree(da->ofill);}
    142:   if (da->e) {PetscFree(da->e);}

    144:   PetscHeaderDestroy(da);
    145:   return(0);
    146: }

    150: /*@C
    151:    DAGetISLocalToGlobalMapping - Accesses the local-to-global mapping in a DA.

    153:    Not Collective

    155:    Input Parameter:
    156: .  da - the distributed array that provides the mapping

    158:    Output Parameter:
    159: .  ltog - the mapping

    161:    Level: intermediate

    163:    Notes:
    164:    This mapping can them be used by VecSetLocalToGlobalMapping() or
    165:    MatSetLocalToGlobalMapping().

    167:    Essentially the same data is returned in the form of an integer array
    168:    with the routine DAGetGlobalIndices().

    170: .keywords: distributed array, destroy

    172: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
    173:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMappingBlck()
    174: @*/
    175: PetscErrorCode PETSCDM_DLLEXPORT DAGetISLocalToGlobalMapping(DA da,ISLocalToGlobalMapping *map)
    176: {
    180:   *map = da->ltogmap;
    181:   return(0);
    182: }

    186: /*@C
    187:    DAGetISLocalToGlobalMappingBlck - Accesses the local-to-global mapping in a DA.

    189:    Not Collective

    191:    Input Parameter:
    192: .  da - the distributed array that provides the mapping

    194:    Output Parameter:
    195: .  ltog - the mapping

    197:    Level: intermediate

    199:    Notes:
    200:    This mapping can them be used by VecSetLocalToGlobalMappingBlock() or
    201:    MatSetLocalToGlobalMappingBlock().

    203:    Essentially the same data is returned in the form of an integer array
    204:    with the routine DAGetGlobalIndices().

    206: .keywords: distributed array, destroy

    208: .seealso: DACreate1d(), DACreate2d(), DACreate3d(), VecSetLocalToGlobalMapping(),
    209:           MatSetLocalToGlobalMapping(), DAGetGlobalIndices(), DAGetISLocalToGlobalMapping()
    210: @*/
    211: PetscErrorCode PETSCDM_DLLEXPORT DAGetISLocalToGlobalMappingBlck(DA da,ISLocalToGlobalMapping *map)
    212: {
    216:   *map = da->ltogmapb;
    217:   return(0);
    218: }