Actual source code: ex18.c
petsc-3.4.5 2014-06-29
2: static char help[] = "Tests DMGetLocalToGlobalMappingBlock().\n\n";
4: #include <petscdmda.h>
8: int main(int argc,char **argv)
9: {
10: PetscMPIInt rank;
11: PetscInt M = 10,N = 8,m = PETSC_DECIDE,n = PETSC_DECIDE;
13: DM da;
14: PetscViewer viewer;
15: Vec local,global;
16: PetscScalar value;
18: PetscInitialize(&argc,&argv,(char*)0,help);
19: PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);
21: /* Read options */
22: PetscOptionsGetInt(NULL,"-M",&M,NULL);
23: PetscOptionsGetInt(NULL,"-N",&N,NULL);
24: PetscOptionsGetInt(NULL,"-m",&m,NULL);
25: PetscOptionsGetInt(NULL,"-n",&n,NULL);
27: /* Create distributed array and get vectors */
28: DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_BOX,
29: M,N,m,n,1,1,NULL,NULL,&da);
30: DMCreateGlobalVector(da,&global);
31: DMCreateLocalVector(da,&local);
33: value = -3.0;
34: VecSet(global,value);
35: DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
36: DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);
38: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
39: value = rank+1;
40: VecScale(local,value);
41: DMLocalToGlobalBegin(da,local,ADD_VALUES,global);
42: DMLocalToGlobalEnd(da,local,ADD_VALUES,global);
44: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
45: DMView(da,viewer);
47: /* Free memory */
48: PetscViewerDestroy(&viewer);
49: VecDestroy(&local);
50: VecDestroy(&global);
51: DMDestroy(&da);
52: PetscFinalize();
53: return 0;
54: }