Actual source code: ex38.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: static char help[] = "Tests DMGlobalToLocal() for 3d DA with stencil width of 2.\n\n";

  4: #include <petscdm.h>
  5: #include <petscdmda.h>

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


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

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

 31:   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);

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