Actual source code: ex1.c
1: /*$Id: ex1.c,v 1.16 2001/08/07 03:04:45 balay Exp $*/
3: static char help[] = "Tests VecView() contour plotting for 2d DAs.nn";
5: #include petscda.h
6: #include petscsys.h
8: int main(int argc,char **argv)
9: {
10: int rank,M = 10,N = 8,m = PETSC_DECIDE,n = PETSC_DECIDE,ierr;
11: PetscTruth flg;
12: DA da;
13: PetscViewer viewer;
14: Vec local,global;
15: PetscScalar value;
16: DAPeriodicType ptype = DA_NONPERIODIC;
17: DAStencilType stype = DA_STENCIL_BOX;
19: PetscInitialize(&argc,&argv,(char*)0,help);
20: PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);
22: /* Read options */
23: PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
24: PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
25: PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
26: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
27: PetscOptionsHasName(PETSC_NULL,"-star_stencil",&flg);
28: if (flg) stype = DA_STENCIL_STAR;
30: /* Create distributed array and get vectors */
31: DACreate2d(PETSC_COMM_WORLD,ptype,stype,
32: M,N,m,n,1,1,PETSC_NULL,PETSC_NULL,&da);
33: DACreateGlobalVector(da,&global);
34: DACreateLocalVector(da,&local);
36: value = -3.0;
37: VecSet(&value,global);
38: DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
39: DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);
41: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
42: value = rank+1;
43: VecScale(&value,local);
44: DALocalToGlobal(da,local,ADD_VALUES,global);
46: DAView(da,viewer);
47: VecView(global,viewer);
49: /* Free memory */
50: PetscViewerDestroy(viewer);
51: VecDestroy(local);
52: VecDestroy(global);
53: DADestroy(da);
54: PetscFinalize();
55: return 0;
56: }
57: