Actual source code: ex34.c
petsc-3.7.7 2017-09-25
1: static const char help[] = "Test DMDAGetOwnershipRanges()\n";
3: #include <petscdm.h>
4: #include <petscdmda.h>
8: int main(int argc,char *argv[])
9: {
11: DM da;
12: PetscInt dim = 2,m,n,p,i;
13: const PetscInt *lx,*ly,*lz;
14: PetscMPIInt rank,size;
16: PetscInitialize(&argc,&argv,0,help);
17: PetscOptionsGetInt(NULL,0,"-dim",&dim,0);
18: switch (dim) {
19: case 2:
20: DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_STAR, -3,-5,PETSC_DECIDE,PETSC_DECIDE,2,1,NULL,NULL,&da);
21: break;
22: case 3:
23: 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);
24: break;
25: default: SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for %D dimensions",dim);
26: }
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_size(PETSC_COMM_WORLD,&size);
30: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
31: for (i=0; i<size; i++) {
32: PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
33: if (i == rank) {
34: PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_SELF,"[%d] lx ly%s\n",rank,dim>2 ? " lz" : "");
35: PetscIntView(m,lx,PETSC_VIEWER_STDOUT_SELF);
36: PetscIntView(n,ly,PETSC_VIEWER_STDOUT_SELF);
37: if (dim > 2) {PetscIntView(n,lz,PETSC_VIEWER_STDOUT_SELF);}
38: }
39: MPI_Barrier(PETSC_COMM_WORLD);
40: }
41: DMDestroy(&da);
42: PetscFinalize();
43: return 0;
44: }