Actual source code: dadist.c

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

  6: #include <private/daimpl.h>    /*I   "petscdmda.h"   I*/

 10: PetscErrorCode  VecDuplicate_MPI_DA(Vec g,Vec* gg)
 11: {
 13:   DM             da;

 16:   PetscObjectQuery((PetscObject)g,"DM",(PetscObject*)&da);
 17:   DMCreateGlobalVector(da,gg);
 18:   PetscLayoutReference(g->map,&(*gg)->map);
 19:   return(0);
 20: }


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

 33:   VecCreate(((PetscObject)da)->comm,g);
 34:   VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
 35:   VecSetType(*g,da->vectype);
 36:   PetscObjectCompose((PetscObject)*g,"DM",(PetscObject)da);
 37:   VecSetLocalToGlobalMapping(*g,da->ltogmap);
 38:   VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);
 39:   VecSetBlockSize(*g,dd->w);
 40:   VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);
 41:   VecSetOperation(*g,VECOP_LOAD,(void(*)(void))VecLoad_Default_DA);
 42:   VecSetOperation(*g,VECOP_DUPLICATE,(void(*)(void))VecDuplicate_MPI_DA);
 43:   return(0);
 44: }

 48: /*@
 49:    DMDACreateNaturalVector - Creates a parallel PETSc vector that
 50:    will hold vector values in the natural numbering, rather than in 
 51:    the PETSc parallel numbering associated with the DMDA.

 53:    Collective on DMDA

 55:    Input Parameter:
 56: .  da - the distributed array

 58:    Output Parameter:
 59: .  g - the distributed global vector

 61:    Level: developer

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

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

 70: .keywords: distributed array, create, global, distributed, vector

 72: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 73:           DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
 74:           DMGlobalToLocalEnd(), DMDALocalToGlobalBegin()
 75: @*/
 76: PetscErrorCode  DMDACreateNaturalVector(DM da,Vec* g)
 77: {
 79:   PetscInt       cnt;
 80:   DM_DA          *dd = (DM_DA*)da->data;

 85:   if (dd->natural) {
 86:     PetscObjectGetReference((PetscObject)dd->natural,&cnt);
 87:     if (cnt == 1) { /* object is not currently used by anyone */
 88:       PetscObjectReference((PetscObject)dd->natural);
 89:       *g   = dd->natural;
 90:     } else {
 91:       VecDuplicate(dd->natural,g);
 92:     }
 93:   } else { /* create the first version of this guy */
 94:     VecCreateMPI(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,g);
 95:     VecSetBlockSize(*g, dd->w);
 96:     PetscObjectReference((PetscObject)*g);
 97:     dd->natural = *g;
 98:   }
 99:   return(0);
100: }