Actual source code: ex38.c

petsc-3.13.6 2020-09-29
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>

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


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

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