Actual source code: ex12.c
petsc-3.7.7 2017-09-25
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>
17: int main(int argc,char **argv)
18: {
19: PetscInt M = -10,N = -8;
20: PetscErrorCode ierr;
21: PetscBool flg = PETSC_FALSE;
22: DM da;
23: Vec global1,global2,global3;
24: DMBoundaryType bx = DM_BOUNDARY_NONE,by = DM_BOUNDARY_NONE;
25: DMDAStencilType stype = DMDA_STENCIL_BOX;
27: PetscInitialize(&argc,&argv,(char*)0,help);
28: PetscOptionsGetBool(NULL,NULL,"-star_stencil",&flg,NULL);
29: if (flg) stype = DMDA_STENCIL_STAR;
31: /* Create distributed array and get vectors */
32: DMDACreate2d(PETSC_COMM_WORLD,bx,by,stype,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&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 0;
52: }