Actual source code: ex34.c
petsc-3.9.4 2018-09-11
1: static const char help[] = "Test DMDAGetOwnershipRanges()\n";
3: #include <petscdm.h>
4: #include <petscdmda.h>
6: int main(int argc,char *argv[])
7: {
9: DM da;
10: PetscViewer vw;
11: PetscInt dim = 2,m,n,p;
12: const PetscInt *lx,*ly,*lz;
13: PetscMPIInt rank;
15: PetscInitialize(&argc,&argv,0,help);if (ierr) return ierr;
16: PetscOptionsGetInt(NULL,0,"-dim",&dim,0);
17: switch (dim) {
18: case 2:
19: DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE, DM_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,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);
23: break;
24: default: SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for %D dimensions",dim);
25: }
26: DMSetFromOptions(da);
27: DMSetUp(da);
28: DMDAGetInfo(da, 0, 0,0,0, &m,&n,&p, 0,0, 0,0,0,0);
29: DMDAGetOwnershipRanges(da,&lx,&ly,&lz);
30: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
32: PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw);
33: PetscViewerASCIIPrintf(vw,"[%d] lx ly%s\n",rank,dim>2 ? " lz" : "");
34: PetscIntView(m,lx,vw);
35: PetscIntView(n,ly,vw);
36: if (dim > 2) {PetscIntView(n,lz,vw);}
37: PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw);
38: PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
40: DMDestroy(&da);
41: PetscFinalize();
42: return ierr;
43: }
46: /*TEST
48: test:
49: nsize: 12
50: args: -dm_view -dim 3 -da_grid_x 11 -da_grid_y 5 -da_grid_z 7
52: TEST*/