Date: 2013-07-02T14:46:20+00:00

Actual source code: ex34.c
petsc-3.4.2 2013-07-02

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

      3: #include <petscdmda.h>

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

     15:   PetscInitialize(&argc,&argv,0,help);
     16:   PetscOptionsGetInt(0,"-dim",&dim,0);
     17:   switch (dim) {
     18:   case 2:
     19:     DMDACreate2d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR, -3,-5,PETSC_DECIDE,PETSC_DECIDE,2,1,NULL,NULL,&da);
     20:     break;
     21:   case 3:
     22:     DMDACreate3d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR, -3,-5,-7,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,2,1,NULL,NULL,NULL,&da);
     23:     break;
     24:   default: SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for %D dimensions",dim);
     25:   }
     26:   DMDAGetInfo(da, 0, 0,0,0, &m,&n,&p, 0,0, 0,0,0,0);
     27:   DMDAGetOwnershipRanges(da,&lx,&ly,&lz);
     28:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
     29:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     30:   for (i=0; i<size; i++) {
     31:     PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
     32:     if (i == rank) {
     33:       PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_SELF,"[%d] lx ly%s\n",rank,dim>2 ? " lz" : "");
     34:       PetscIntView(m,lx,PETSC_VIEWER_STDOUT_SELF);
     35:       PetscIntView(n,ly,PETSC_VIEWER_STDOUT_SELF);
     36:       if (dim > 2) {PetscIntView(n,lz,PETSC_VIEWER_STDOUT_SELF);}
     37:     }
     38:     MPI_Barrier(PETSC_COMM_WORLD);
     39:   }
     40:   DMDestroy(&da);
     41:   PetscFinalize();
     42:   return 0;
     43: }