Actual source code: ex12.c

petsc-3.3-p7 2013-05-11
  2: static char help[] = "Tests DMGetGlobalVector() and DMRestoreGlobalVector().\n\n";

  4: /*
  5: Use the options
  6:      -da_grid_x <nx> - number of grid points in x direction, if M < 0
  7:      -da_grid_y <ny> - number of grid points in y direction, if N < 0
  8:      -da_processors_x <MX> number of processors in x directio
  9:      -da_processors_y <MY> number of processors in x direction
 10: */

 12: #include <petscdmda.h>

 16: int main(int argc,char **argv)
 17: {
 18:   PetscInt       M = -10,N = -8;
 20:   PetscBool      flg = PETSC_FALSE;
 21:   DM             da;
 22:   Vec            global1,global2,global3;
 23:   DMDABoundaryType bx = DMDA_BOUNDARY_NONE,by = DMDA_BOUNDARY_NONE;
 24:   DMDAStencilType  stype = DMDA_STENCIL_BOX;

 26:   PetscInitialize(&argc,&argv,(char*)0,help);
 27:   PetscOptionsGetBool(PETSC_NULL,"-star_stencil",&flg,PETSC_NULL);
 28:   if (flg) stype = DMDA_STENCIL_STAR;
 29: 
 30:   /* Create distributed array and get vectors */
 31:   DMDACreate2d(PETSC_COMM_WORLD,bx,by,stype,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,PETSC_NULL,PETSC_NULL,&da);
 32:   DMGetGlobalVector(da,&global1);
 33:   DMGetGlobalVector(da,&global2);
 34:   DMRestoreGlobalVector(da,&global1);
 35:   DMRestoreGlobalVector(da,&global2);
 36:   DMGetGlobalVector(da,&global1);
 37:   DMGetGlobalVector(da,&global3);
 38:   DMGetGlobalVector(da,&global2);
 39:   DMRestoreGlobalVector(da,&global1);
 40:   DMRestoreGlobalVector(da,&global3);
 41:   DMRestoreGlobalVector(da,&global2);
 42:   DMGetGlobalVector(da,&global1);
 43:   DMGetGlobalVector(da,&global3);
 44:   DMGetGlobalVector(da,&global2);
 45:   DMRestoreGlobalVector(da,&global1);
 46:   DMRestoreGlobalVector(da,&global3);
 47:   DMRestoreGlobalVector(da,&global2);
 48:   DMDestroy(&da);
 49:   PetscFinalize();
 50:   return 0;
 51: }
 52: