Actual source code: dadist.c

  1: /*$Id: dadist.c,v 1.29 2001/03/23 23:25:00 balay Exp $*/
  2: 
  3: /*
  4:   Code for manipulating distributed regular arrays in parallel.
  5: */

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

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

 15:    Collective on DA

 17:    Input Parameter:
 18: .  da - the distributed array

 20:    Output Parameter:
 21: .  g - the distributed global vector

 23:    Level: beginner

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

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

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

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

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

 59:    Collective on DA

 61:    Input Parameter:
 62: .  da - the distributed array

 64:    Output Parameter:
 65: .  g - the distributed global vector

 67:    Level: developer

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

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

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

 78: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 79:           DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
 80:           DAGlobalToLocalEnd(), DALocalToGlobal()
 81: @*/
 82: int DACreateNaturalVector(DA da,Vec* g)
 83: {
 84:   int cnt,ierr;

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