Actual source code: ex51.c

  1: static char help[] = "Tests DMDAVecGetArrayDOF()\n";
  2: #include <petscdm.h>
  3: #include <petscdmda.h>

  5: int main(int argc, char *argv[])
  6: {
  7:   DM             da, daX, daY;
  8:   DMDALocalInfo  info;
  9:   MPI_Comm       commX, commY;
 10:   Vec            basisX, basisY;
 11:   PetscScalar    **arrayX, **arrayY;
 12:   const PetscInt *lx, *ly;
 13:   PetscInt       M     = 3, N = 3;
 14:   PetscInt       p     = 1;
 15:   PetscInt       numGP = 3;
 16:   PetscInt       dof   = 2*(p+1)*numGP;
 17:   PetscMPIInt    rank, subsize, subrank;

 19:   PetscInitialize(&argc,&argv,0,help);
 20:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
 21:   /* Create 2D DMDA */
 22:   DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da);
 23:   DMSetFromOptions(da);
 24:   DMSetUp(da);
 25:   /* Create 1D DMDAs along two directions. */
 26:   DMDAGetOwnershipRanges(da, &lx, &ly, NULL);
 27:   DMDAGetLocalInfo(da, &info);
 28:   /* Partitioning in the X direction makes a subcomm extending in the Y direction and vice-versa. */
 29:   DMDAGetProcessorSubsets(da, DM_X, &commY);
 30:   DMDAGetProcessorSubsets(da, DM_Y, &commX);
 31:   MPI_Comm_size(commX, &subsize);
 32:   MPI_Comm_rank(commX, &subrank);
 33:   PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d]X subrank: %d subsize: %d\n", rank, subrank, subsize);
 34:   PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
 35:   MPI_Comm_size(commY, &subsize);
 36:   MPI_Comm_rank(commY, &subrank);
 37:   PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d]Y subrank: %d subsize: %d\n", rank, subrank, subsize);
 38:   PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
 39:   DMDACreate1d(commX, DM_BOUNDARY_NONE, info.mx, dof, 1, lx, &daX);
 40:   DMSetUp(daX);
 41:   DMDACreate1d(commY, DM_BOUNDARY_NONE, info.my, dof, 1, ly, &daY);
 42:   DMSetUp(daY);
 43:   /* Create 1D vectors for basis functions */
 44:   DMGetGlobalVector(daX, &basisX);
 45:   DMGetGlobalVector(daY, &basisY);
 46:   /* Extract basis functions */
 47:   DMDAVecGetArrayDOF(daX, basisX, &arrayX);
 48:   DMDAVecGetArrayDOF(daY, basisY, &arrayY);
 49:   /*arrayX[i][ndof]; */
 50:   /*arrayY[j][ndof]; */
 51:   DMDAVecRestoreArrayDOF(daX, basisX, &arrayX);
 52:   DMDAVecRestoreArrayDOF(daY, basisY, &arrayY);
 53:   /* Return basis vectors */
 54:   DMRestoreGlobalVector(daX, &basisX);
 55:   DMRestoreGlobalVector(daY, &basisY);
 56:   /* Cleanup */
 57:   MPI_Comm_free(&commX);
 58:   MPI_Comm_free(&commY);
 59:   DMDestroy(&daX);
 60:   DMDestroy(&daY);
 61:   DMDestroy(&da);
 62:   PetscFinalize();
 63:   return 0;
 64: }

 66: /*TEST

 68:    test:
 69:       nsize: 2

 71: TEST*/