Actual source code: ex24.c
2: static char help[] = "Tests DMLocalToGlobal() for dof > 1\n\n";
4: #include <petscdm.h>
5: #include <petscdmda.h>
7: int main(int argc,char **argv)
8: {
9: PetscInt M = 6,N = 5,m = PETSC_DECIDE,n = PETSC_DECIDE,i,j,is,js,in,jen;
10: DM da;
11: Vec local,global;
12: PetscScalar ***l;
14: PetscInitialize(&argc,&argv,(char*)0,help);
15: /* Create distributed array and get vectors */
16: DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,m,n,3,1,NULL,NULL,&da);
17: DMSetFromOptions(da);
18: DMSetUp(da);
19: DMCreateGlobalVector(da,&global);
20: DMCreateLocalVector(da,&local);
22: DMDAGetCorners(da,&is,&js,0,&in,&jen,0);
23: DMDAVecGetArrayDOF(da,local,&l);
24: for (i=is; i<is+in; i++) {
25: for (j=js; j<js+jen; j++) {
26: l[j][i][0] = 3*(i + j*M);
27: l[j][i][1] = 3*(i + j*M) + 1;
28: l[j][i][2] = 3*(i + j*M) + 2;
29: }
30: }
31: DMDAVecRestoreArrayDOF(da,local,&l);
32: DMLocalToGlobalBegin(da,local,ADD_VALUES,global);
33: DMLocalToGlobalEnd(da,local,ADD_VALUES,global);
35: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
37: /* Free memory */
38: VecDestroy(&local);
39: VecDestroy(&global);
40: DMDestroy(&da);
41: PetscFinalize();
42: return 0;
43: }
45: /*TEST
47: test:
48: filter: grep -v -i Process
49: output_file: output/ex24_1.out
51: test:
52: suffix: 2
53: nsize: 2
54: filter: grep -v -i Process
55: output_file: output/ex24_2.out
57: test:
58: suffix: 3
59: nsize: 3
60: filter: grep -v -i Process
61: output_file: output/ex24_2.out
63: test:
64: suffix: 4
65: nsize: 4
66: filter: grep -v -i Process
67: output_file: output/ex24_2.out
69: test:
70: suffix: 5
71: nsize: 5
72: filter: grep -v -i Process
73: output_file: output/ex24_2.out
75: test:
76: suffix: 6
77: nsize: 6
78: filter: grep -v -i Process
79: output_file: output/ex24_2.out
81: TEST*/