Actual source code: dadist.c

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

 5:  #include src/dm/da/daimpl.h

  9: /*@C
 10:    DACreateGlobalVector - Creates a parallel PETSc vector that
 11:    may be used with the DAXXX routines.

 13:    Collective on DA

 15:    Input Parameter:
 16: .  da - the distributed array

 18:    Output Parameter:
 19: .  g - the distributed global vector

 21:    Level: beginner

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

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

 29: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 30:           DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
 31:           DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateNaturalVector()
 32: @*/
 33: PetscErrorCode DACreateGlobalVector(DA da,Vec* g)
 34: {

 40:   VecCreateMPI(da->comm,da->Nlocal,PETSC_DETERMINE,g);
 41:   PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);
 42:   VecSetLocalToGlobalMapping(*g,da->ltogmap);
 43:   VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);
 44:   VecSetBlockSize(*g,da->w);
 45:   VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);
 46:   VecSetOperation(*g,VECOP_LOADINTOVECTOR,(void(*)(void))VecLoadIntoVector_Binary_DA);
 47:   return(0);
 48: }

 52: /*@C
 53:    DACreateNaturalVector - Creates a parallel PETSc vector that
 54:    will hold vector values in the natural numbering, rather than in 
 55:    the PETSc parallel numbering associated with the DA.

 57:    Collective on DA

 59:    Input Parameter:
 60: .  da - the distributed array

 62:    Output Parameter:
 63: .  g - the distributed global vector

 65:    Level: developer

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

 71:    The number of local entries in the vector on each process is the same
 72:    as in a vector created with DACreateGlobalVector().

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

 76: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 77:           DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
 78:           DAGlobalToLocalEnd(), DALocalToGlobal()
 79: @*/
 80: PetscErrorCode DACreateNaturalVector(DA da,Vec* g)
 81: {
 83:   PetscInt cnt;

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