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: #undef __FUNCT__
10: int main(int argc,char **argv)
11: {
12: int rank,M = 10,N = 8,m = PETSC_DECIDE,n = PETSC_DECIDE,ierr;
13: PetscTruth flg;
14: DA da;
15: PetscViewer viewer;
16: Vec local,global;
17: PetscScalar value;
18: DAPeriodicType ptype = DA_NONPERIODIC;
19: DAStencilType stype = DA_STENCIL_BOX;
21: PetscInitialize(&argc,&argv,(char*)0,help);
22: PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);
24: /* Read options */
25: PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
26: PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
27: PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
28: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
29: PetscOptionsHasName(PETSC_NULL,"-star_stencil",&flg);
30: if (flg) stype = DA_STENCIL_STAR;
32: /* Create distributed array and get vectors */
33: DACreate2d(PETSC_COMM_WORLD,ptype,stype,
34: M,N,m,n,1,1,PETSC_NULL,PETSC_NULL,&da);
35: DACreateGlobalVector(da,&global);
36: DACreateLocalVector(da,&local);
38: value = -3.0;
39: VecSet(&value,global);
40: DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
41: DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);
43: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
44: value = rank+1;
45: VecScale(&value,local);
46: DALocalToGlobal(da,local,ADD_VALUES,global);
48: DAView(da,viewer);
49: VecView(global,viewer);
51: /* Free memory */
52: PetscViewerDestroy(viewer);
53: VecDestroy(local);
54: VecDestroy(global);
55: DADestroy(da);
56: PetscFinalize();
57: return 0;
58: }
59: