Actual source code: ex1.c
2: static char help[] = "Tests various DA routines.\n\n";
4: #include petscda.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: DA 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(PETSC_NULL,"-M",&M,PETSC_NULL);
23: PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
24: PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
25: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
27: /* Create distributed array and get vectors */
28: DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,
29: M,N,m,n,1,1,PETSC_NULL,PETSC_NULL,&da);
30: DACreateGlobalVector(da,&global);
31: DACreateLocalVector(da,&local);
33: value = -3.0;
34: VecSet(global,value);
35: DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
36: DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);
38: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
39: value = rank+1;
40: VecScale(local,value);
41: DALocalToGlobal(da,local,ADD_VALUES,global);
43: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_NATIVE);
44: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
45: DAView(da,viewer);
47: /* Free memory */
48: PetscViewerDestroy(viewer);
49: VecDestroy(local);
50: VecDestroy(global);
51: DADestroy(da);
52: PetscFinalize();
53: return 0;
54: }
55: