Actual source code: ex38.c

petsc-3.4.2 2013-07-02
  2: static char help[] = "Tests DMGlobalToLocal() for 3d DA with stencil width of 2.\n\n";

  4: #include <petscdmda.h>

  8: int main(int argc,char **argv)
  9: {
 10:   PetscInt         N             = 3,M=2,P=4,dof=1,rstart,rend,i;
 11:   PetscInt         stencil_width = 2;
 12:   PetscErrorCode   ierr;
 13:   PetscMPIInt      rank;
 14:   DMDABoundaryType bx           = DMDA_BOUNDARY_NONE,by = DMDA_BOUNDARY_NONE,bz = DMDA_BOUNDARY_NONE;
 15:   DMDAStencilType  stencil_type = DMDA_STENCIL_STAR;
 16:   DM               da;
 17:   Vec              global,local;


 20:   PetscInitialize(&argc,&argv,(char*)0,help);
 21:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 22:   PetscOptionsGetInt(NULL,"-M",&M,NULL);
 23:   PetscOptionsGetInt(NULL,"-N",&N,NULL);
 24:   PetscOptionsGetInt(NULL,"-P",&P,NULL);
 25:   PetscOptionsGetInt(NULL,"-dof",&dof,NULL);
 26:   PetscOptionsGetInt(NULL,"-stencil_width",&stencil_width,NULL);

 28:   PetscOptionsGetInt(NULL,"-stencil_type",(PetscInt*)&stencil_type,NULL);

 30:   DMDACreate3d(PETSC_COMM_WORLD,bx,by,bz,stencil_type,M,N,P,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,dof,stencil_width,0,0,0,&da);

 32:   DMCreateGlobalVector(da,&global);
 33:   VecGetOwnershipRange(global,&rstart,&rend);
 34:   for (i=rstart; i<rend; i++) {VecSetValue(global,i,(PetscReal)(i + 100*rank),INSERT_VALUES);}
 35:   VecAssemblyBegin(global);
 36:   VecAssemblyEnd(global);
 37:   DMCreateLocalVector(da,&local);
 38:   VecSet(local,-1);
 39:   DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
 40:   DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);
 41:   if (!rank) {VecView(local,0);}
 42:   DMDestroy(&da);
 43:   VecDestroy(&local);
 44:   VecDestroy(&global);
 45:   PetscFinalize();
 46:   return 0;
 47: }