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

  9: #undef __FUNCT__  
 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: {

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

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

 58:    Collective on DA

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

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

 66:    Level: developer

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

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

 74: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
 75:           DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
 76:           DAGlobalToLocalEnd(), DALocalToGlobal()
 77: @*/
 78: int DACreateNaturalVector(DA da,Vec* g)
 79: {
 80:   int cnt,ierr;

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