Actual source code: dadist.c


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

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

  8: PetscErrorCode  VecDuplicate_MPI_DA(Vec g,Vec *gg)
  9: {
 11:   DM             da;
 12:   PetscLayout    map;

 15:   VecGetDM(g, &da);
 16:   DMCreateGlobalVector(da,gg);
 17:   VecGetLayout(g,&map);
 18:   VecSetLayout(*gg,map);
 19:   return(0);
 20: }

 22: PetscErrorCode  DMCreateGlobalVector_DA(DM da,Vec *g)
 23: {
 25:   DM_DA          *dd = (DM_DA*)da->data;

 30:   VecCreate(PetscObjectComm((PetscObject)da),g);
 31:   VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
 32:   VecSetBlockSize(*g,dd->w);
 33:   VecSetType(*g,da->vectype);
 34:   VecSetDM(*g, da);
 35:   VecSetLocalToGlobalMapping(*g,da->ltogmap);
 36:   VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);
 37:   VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);
 38:   VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);
 39:   return(0);
 40: }

 42: /*@
 43:    DMDACreateNaturalVector - Creates a parallel PETSc vector that
 44:    will hold vector values in the natural numbering, rather than in
 45:    the PETSc parallel numbering associated with the DMDA.

 47:    Collective

 49:    Input Parameter:
 50: .  da - the distributed array

 52:    Output Parameter:
 53: .  g - the distributed global vector

 55:    Level: developer

 57:    Note:
 58:    The output parameter, g, is a regular PETSc vector that should be destroyed
 59:    with a call to VecDestroy() when usage is finished.

 61:    The number of local entries in the vector on each process is the same
 62:    as in a vector created with DMCreateGlobalVector().

 64: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 65:           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
 66:           DMGlobalToLocalEnd(), DMLocalToGlobalBegin()
 67: @*/
 68: PetscErrorCode  DMDACreateNaturalVector(DM da,Vec *g)
 69: {
 71:   PetscInt       cnt;
 72:   DM_DA          *dd = (DM_DA*)da->data;

 77:   if (dd->natural) {
 78:     PetscObjectGetReference((PetscObject)dd->natural,&cnt);
 79:     if (cnt == 1) { /* object is not currently used by anyone */
 80:       PetscObjectReference((PetscObject)dd->natural);
 81:       *g   = dd->natural;
 82:     } else {
 83:       VecDuplicate(dd->natural,g);
 84:     }
 85:   } else { /* create the first version of this guy */
 86:     VecCreate(PetscObjectComm((PetscObject)da),g);
 87:     VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
 88:     VecSetBlockSize(*g, dd->w);
 89:     VecSetType(*g,da->vectype);
 90:     PetscObjectReference((PetscObject)*g);

 92:     dd->natural = *g;
 93:   }
 94:   return(0);
 95: }