Actual source code: ex34.c

  1: static const char help[] = "Test DMDAGetOwnershipRanges()\n";

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

  6: int main(int argc,char *argv[])
  7: {
  8:   DM             da;
  9:   PetscViewer    vw;
 10:   PetscInt       dim = 2,m,n,p;
 11:   const PetscInt *lx,*ly,*lz;
 12:   PetscMPIInt    rank;

 14:   PetscInitialize(&argc,&argv,0,help);
 15:   PetscOptionsGetInt(NULL,0,"-dim",&dim,0);
 16:   switch (dim) {
 17:   case 2:
 18:     DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_STAR, 3,5,PETSC_DECIDE,PETSC_DECIDE,2,1,NULL,NULL,&da);
 19:     break;
 20:   case 3:
 21:     DMDACreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR, 3,5,7,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,2,1,NULL,NULL,NULL,&da);
 22:     break;
 23:   default: SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for %D dimensions",dim);
 24:   }
 25:   DMSetFromOptions(da);
 26:   DMSetUp(da);
 27:   DMDAGetInfo(da, 0, 0,0,0, &m,&n,&p, 0,0, 0,0,0,0);
 28:   DMDAGetOwnershipRanges(da,&lx,&ly,&lz);
 29:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

 31:   PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw);
 32:   PetscViewerASCIIPrintf(vw,"[%d] lx ly%s\n",rank,dim>2 ? " lz" : "");
 33:   PetscIntView(m,lx,vw);
 34:   PetscIntView(n,ly,vw);
 35:   if (dim > 2) PetscIntView(n,lz,vw);
 36:   PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw);
 37:   PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);

 39:   DMDestroy(&da);
 40:   PetscFinalize();
 41:   return 0;
 42: }

 44: /*TEST

 46:    test:
 47:       nsize: 12
 48:       args: -dm_view -dim 3 -da_grid_x 11 -da_grid_y 5 -da_grid_z 7

 50: TEST*/