Actual source code: ex12.c

petsc-3.8.4 2018-03-24
Report Typos and Errors

  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 <petscdm.h>
 13:  #include <petscdmda.h>

 15: int main(int argc,char **argv)
 16: {
 17:   PetscInt         M = 10,N = 8;
 18:   PetscErrorCode   ierr;
 19:   PetscBool        flg = PETSC_FALSE;
 20:   DM               da;
 21:   Vec              global1,global2,global3;
 22:   DMBoundaryType   bx    = DM_BOUNDARY_NONE,by = DM_BOUNDARY_NONE;
 23:   DMDAStencilType  stype = DMDA_STENCIL_BOX;

 25:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 26:   PetscOptionsGetBool(NULL,NULL,"-star_stencil",&flg,NULL);
 27:   if (flg) stype = DMDA_STENCIL_STAR;

 29:   /* Create distributed array and get vectors */
 30:   DMDACreate2d(PETSC_COMM_WORLD,bx,by,stype,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da);
 31:   DMSetFromOptions(da);
 32:   DMSetUp(da);
 33:   DMGetGlobalVector(da,&global1);
 34:   DMGetGlobalVector(da,&global2);
 35:   DMRestoreGlobalVector(da,&global1);
 36:   DMRestoreGlobalVector(da,&global2);
 37:   DMGetGlobalVector(da,&global1);
 38:   DMGetGlobalVector(da,&global3);
 39:   DMGetGlobalVector(da,&global2);
 40:   DMRestoreGlobalVector(da,&global1);
 41:   DMRestoreGlobalVector(da,&global3);
 42:   DMRestoreGlobalVector(da,&global2);
 43:   DMGetGlobalVector(da,&global1);
 44:   DMGetGlobalVector(da,&global3);
 45:   DMGetGlobalVector(da,&global2);
 46:   DMRestoreGlobalVector(da,&global1);
 47:   DMRestoreGlobalVector(da,&global3);
 48:   DMRestoreGlobalVector(da,&global2);
 49:   DMDestroy(&da);
 50:   PetscFinalize();
 51:   return ierr;
 52: }