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.\n\n";
5: #include petscda.h
6: #include petscsys.h
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;
20: #if defined(PETSC_HAVE_MATLAB) && !defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_SINGLE)
21: PetscViewer mviewer;
22: #endif
24: PetscInitialize(&argc,&argv,(char*)0,help);
25: PetscViewerDrawOpen(PETSC_COMM_WORLD,0,"",300,0,300,300,&viewer);
26: #if defined(PETSC_HAVE_MATLAB) && !defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_SINGLE)
27: PetscViewerMatlabOpen(PETSC_COMM_WORLD,"tmp.mat",PETSC_FILE_CREATE,&mviewer);
28: #endif
30: /* Read options */
31: PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
32: PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
33: PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);
34: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
35: PetscOptionsHasName(PETSC_NULL,"-star_stencil",&flg);
36: if (flg) stype = DA_STENCIL_STAR;
38: /* Create distributed array and get vectors */
39: DACreate2d(PETSC_COMM_WORLD,ptype,stype,M,N,m,n,1,1,PETSC_NULL,PETSC_NULL,&da);
40: DACreateGlobalVector(da,&global);
41: DACreateLocalVector(da,&local);
43: value = -3.0;
44: VecSet(&value,global);
45: DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
46: DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);
48: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
49: value = rank+1;
50: VecScale(&value,local);
51: DALocalToGlobal(da,local,ADD_VALUES,global);
53: DAView(da,viewer);
54: VecView(global,viewer);
55: #if defined(PETSC_HAVE_MATLAB) && !defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_SINGLE)
56: DAView(da,mviewer);
57: VecView(global,mviewer);
58: #endif
60: /* Free memory */
61: #if defined(PETSC_HAVE_MATLAB) && !defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_SINGLE)
62: PetscViewerDestroy(mviewer);
63: #endif
64: PetscViewerDestroy(viewer);
65: VecDestroy(local);
66: VecDestroy(global);
67: DADestroy(da);
68: PetscFinalize();
69: return 0;
70: }
71: