xref: /petsc/src/dm/tutorials/ex12.c (revision 2ff79c18c26c94ed8cb599682f680f231dca6444)
1 static char help[] = "Tests DMGetGlobalVector() and DMRestoreGlobalVector().\n\n";
2 
3 /*
4 Use the options
5      -da_grid_x <nx> - number of grid points in x direction, if M < 0
6      -da_grid_y <ny> - number of grid points in y direction, if N < 0
7      -da_processors_x <MX> number of processors in x directio
8      -da_processors_y <MY> number of processors in x direction
9 */
10 
11 #include <petscdm.h>
12 #include <petscdmda.h>
13 
14 int main(int argc, char **argv)
15 {
16   PetscInt        M = 10, N = 8;
17   PetscBool       flg = PETSC_FALSE;
18   DM              da;
19   Vec             global1, global2, global3;
20   DMBoundaryType  bx = DM_BOUNDARY_NONE, by = DM_BOUNDARY_NONE;
21   DMDAStencilType stype = DMDA_STENCIL_BOX;
22 
23   PetscFunctionBeginUser;
24   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
25   PetscCall(PetscOptionsGetBool(NULL, NULL, "-star_stencil", &flg, NULL));
26   if (flg) stype = DMDA_STENCIL_STAR;
27 
28   /* Create distributed array and get vectors */
29   PetscCall(DMDACreate2d(PETSC_COMM_WORLD, bx, by, stype, M, N, PETSC_DECIDE, PETSC_DECIDE, 1, 1, NULL, NULL, &da));
30   PetscCall(DMSetFromOptions(da));
31   PetscCall(DMSetUp(da));
32   PetscCall(DMGetGlobalVector(da, &global1));
33   PetscCall(DMGetGlobalVector(da, &global2));
34   PetscCall(DMRestoreGlobalVector(da, &global1));
35   PetscCall(DMRestoreGlobalVector(da, &global2));
36   PetscCall(DMGetGlobalVector(da, &global1));
37   PetscCall(DMGetGlobalVector(da, &global3));
38   PetscCall(DMGetGlobalVector(da, &global2));
39   PetscCall(DMRestoreGlobalVector(da, &global1));
40   PetscCall(DMRestoreGlobalVector(da, &global3));
41   PetscCall(DMRestoreGlobalVector(da, &global2));
42   PetscCall(DMGetGlobalVector(da, &global1));
43   PetscCall(DMGetGlobalVector(da, &global3));
44   PetscCall(DMGetGlobalVector(da, &global2));
45   PetscCall(DMRestoreGlobalVector(da, &global1));
46   PetscCall(DMRestoreGlobalVector(da, &global3));
47   PetscCall(DMRestoreGlobalVector(da, &global2));
48   PetscCall(DMDestroy(&da));
49   PetscCall(PetscFinalize());
50   return 0;
51 }
52 
53 /*TEST
54 
55    test:
56      output_file: output/empty.out
57 
58 TEST*/
59