1 static const char help[] = "Test DMDAGetOwnershipRanges()\n"; 2 3 #include <petscdm.h> 4 #include <petscdmda.h> 5 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; 13 14 PetscCall(PetscInitialize(&argc,&argv,0,help)); 15 PetscCall(PetscOptionsGetInt(NULL,0,"-dim",&dim,0)); 16 switch (dim) { 17 case 2: 18 PetscCall(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 PetscCall(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 %" PetscInt_FMT " dimensions",dim); 24 } 25 PetscCall(DMSetFromOptions(da)); 26 PetscCall(DMSetUp(da)); 27 PetscCall(DMDAGetInfo(da, 0, 0,0,0, &m,&n,&p, 0,0, 0,0,0,0)); 28 PetscCall(DMDAGetOwnershipRanges(da,&lx,&ly,&lz)); 29 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); 30 31 PetscCall(PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw)); 32 PetscCall(PetscViewerASCIIPrintf(vw,"[%d] lx ly%s\n",rank,dim>2 ? " lz" : "")); 33 PetscCall(PetscIntView(m,lx,vw)); 34 PetscCall(PetscIntView(n,ly,vw)); 35 if (dim > 2) PetscCall(PetscIntView(n,lz,vw)); 36 PetscCall(PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw)); 37 PetscCall(PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD)); 38 39 PetscCall(DMDestroy(&da)); 40 PetscCall(PetscFinalize()); 41 return 0; 42 } 43 44 /*TEST 45 46 test: 47 nsize: 12 48 args: -dm_view -dim 3 -da_grid_x 11 -da_grid_y 5 -da_grid_z 7 49 50 TEST*/ 51