Actual source code: ex34.c

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

  3: #include <petscdm.h>
  4: #include <petscdmda.h>

  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;

 15:   PetscInitialize(&argc, &argv, 0, help);
 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:
 25:     SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "No support for %" PetscInt_FMT " dimensions", dim);
 26:   }
 27:   DMSetFromOptions(da);
 28:   DMSetUp(da);
 29:   DMDAGetInfo(da, 0, 0, 0, 0, &m, &n, &p, 0, 0, 0, 0, 0, 0);
 30:   DMDAGetOwnershipRanges(da, &lx, &ly, &lz);
 31:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);

 33:   PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD, PETSC_COMM_SELF, &vw);
 34:   PetscViewerASCIIPrintf(vw, "[%d] lx ly%s\n", rank, dim > 2 ? " lz" : "");
 35:   PetscIntView(m, lx, vw);
 36:   PetscIntView(n, ly, vw);
 37:   if (dim > 2) PetscIntView(n, lz, vw);
 38:   PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD, PETSC_COMM_SELF, &vw);
 39:   PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);

 41:   DMDestroy(&da);
 42:   PetscFinalize();
 43:   return 0;
 44: }

 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*/