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 PetscFunctionBeginUser; 15 PetscCall(PetscInitialize(&argc,&argv,0,help)); 16 PetscCall(PetscOptionsGetInt(NULL,0,"-dim",&dim,0)); 17 switch (dim) { 18 case 2: 19 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)); 20 break; 21 case 3: 22 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)); 23 break; 24 default: SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for %" PetscInt_FMT " dimensions",dim); 25 } 26 PetscCall(DMSetFromOptions(da)); 27 PetscCall(DMSetUp(da)); 28 PetscCall(DMDAGetInfo(da, 0, 0,0,0, &m,&n,&p, 0,0, 0,0,0,0)); 29 PetscCall(DMDAGetOwnershipRanges(da,&lx,&ly,&lz)); 30 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); 31 32 PetscCall(PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw)); 33 PetscCall(PetscViewerASCIIPrintf(vw,"[%d] lx ly%s\n",rank,dim>2 ? " lz" : "")); 34 PetscCall(PetscIntView(m,lx,vw)); 35 PetscCall(PetscIntView(n,ly,vw)); 36 if (dim > 2) PetscCall(PetscIntView(n,lz,vw)); 37 PetscCall(PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&vw)); 38 PetscCall(PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD)); 39 40 PetscCall(DMDestroy(&da)); 41 PetscCall(PetscFinalize()); 42 return 0; 43 } 44 45 /*TEST 46 47 test: 48 nsize: 12 49 args: -dm_view -dim 3 -da_grid_x 11 -da_grid_y 5 -da_grid_z 7 50 51 TEST*/ 52