Actual source code: ex38.c
2: static char help[] = "Tests DMGlobalToLocal() for 3d DA with stencil width of 2.\n\n";
4: #include <petscdm.h>
5: #include <petscdmda.h>
7: int main(int argc, char **argv)
8: {
9: PetscInt N = 3, M = 2, P = 4, dof = 1, rstart, rend, i;
10: PetscInt stencil_width = 2;
11: PetscMPIInt rank;
12: DMBoundaryType bx = DM_BOUNDARY_NONE, by = DM_BOUNDARY_NONE, bz = DM_BOUNDARY_NONE;
13: DMDAStencilType stencil_type = DMDA_STENCIL_STAR;
14: DM da;
15: Vec global, local;
18: PetscInitialize(&argc, &argv, (char *)0, help);
19: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
20: PetscOptionsGetInt(NULL, NULL, "-M", &M, NULL);
21: PetscOptionsGetInt(NULL, NULL, "-N", &N, NULL);
22: PetscOptionsGetInt(NULL, NULL, "-P", &P, NULL);
23: PetscOptionsGetInt(NULL, NULL, "-dof", &dof, NULL);
24: PetscOptionsGetInt(NULL, NULL, "-stencil_width", &stencil_width, NULL);
25: PetscOptionsGetInt(NULL, NULL, "-stencil_type", (PetscInt *)&stencil_type, NULL);
27: DMDACreate3d(PETSC_COMM_WORLD, bx, by, bz, stencil_type, M, N, P, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, dof, stencil_width, 0, 0, 0, &da);
28: DMSetFromOptions(da);
29: DMSetUp(da);
30: DMCreateGlobalVector(da, &global);
31: VecGetOwnershipRange(global, &rstart, &rend);
32: for (i = rstart; i < rend; i++) VecSetValue(global, i, (PetscReal)(i + 100 * rank), INSERT_VALUES);
33: VecAssemblyBegin(global);
34: VecAssemblyEnd(global);
35: DMCreateLocalVector(da, &local);
36: VecSet(local, -1);
37: DMGlobalToLocalBegin(da, global, INSERT_VALUES, local);
38: DMGlobalToLocalEnd(da, global, INSERT_VALUES, local);
39: if (rank == 0) VecView(local, 0);
40: DMDestroy(&da);
41: VecDestroy(&local);
42: VecDestroy(&global);
43: PetscFinalize();
44: return 0;
45: }