Actual source code: ex7.c
2: static char help[] = "Tests DALocalToLocalxxx().\n\n";
4: #include petscda.h
5: #include petscsys.h
9: int main(int argc,char **argv)
10: {
11: PetscMPIInt rank;
12: PetscInt M=8,dof=1,stencil_width=1,i,start,end,P=5,N = 6,m=PETSC_DECIDE,n=PETSC_DECIDE,p=PETSC_DECIDE,pt = 0,st = 0;
14: PetscTruth flg,flg2,flg3;
15: DAPeriodicType periodic;
16: DAStencilType stencil_type;
17: DA da;
18: Vec local,global,local_copy;
19: PetscScalar value;
20: PetscReal norm,work;
21: PetscViewer viewer;
22: char filename[64];
23: FILE *file;
25: PetscInitialize(&argc,&argv,(char*)0,help);
27: PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
28: PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
29: PetscOptionsGetInt(PETSC_NULL,"-dof",&dof,PETSC_NULL);
30: PetscOptionsGetInt(PETSC_NULL,"-stencil_width",&stencil_width,PETSC_NULL);
31: PetscOptionsGetInt(PETSC_NULL,"-periodic",&pt,PETSC_NULL);
32: periodic = (DAPeriodicType) pt;
33: PetscOptionsGetInt(PETSC_NULL,"-stencil_type",&st,PETSC_NULL);
34: stencil_type = (DAStencilType) st;
36: PetscOptionsHasName(PETSC_NULL,"-2d",&flg2);
37: PetscOptionsHasName(PETSC_NULL,"-3d",&flg3);
38: if (flg2) {
39: DACreate2d(PETSC_COMM_WORLD,periodic,stencil_type,M,N,m,n,dof,stencil_width,
40: PETSC_NULL,PETSC_NULL,&da);
41: } else if (flg3) {
42: DACreate3d(PETSC_COMM_WORLD,periodic,stencil_type,M,N,P,m,n,p,dof,stencil_width,
43: PETSC_NULL,PETSC_NULL,PETSC_NULL,&da);
44: }
45: else {
46: DACreate1d(PETSC_COMM_WORLD,periodic,M,dof,stencil_width,PETSC_NULL,&da);
47: }
49: DACreateGlobalVector(da,&global);
50: DACreateLocalVector(da,&local);
51: VecDuplicate(local,&local_copy);
53:
54: /* zero out vectors so that ghostpoints are zero */
55: value = 0;
56: VecSet(local,value);
57: VecSet(local_copy,value);
59: VecGetOwnershipRange(global,&start,&end);
60: for (i=start; i<end; i++) {
61: value = i + 1;
62: VecSetValues(global,1,&i,&value,INSERT_VALUES);
63: }
64: VecAssemblyBegin(global);
65: VecAssemblyEnd(global);
67: DAGlobalToLocalBegin(da,global,INSERT_VALUES,local);
68: DAGlobalToLocalEnd(da,global,INSERT_VALUES,local);
71: DALocalToLocalBegin(da,local,INSERT_VALUES,local_copy);
72: DALocalToLocalEnd(da,local,INSERT_VALUES,local_copy);
74: PetscOptionsHasName(PETSC_NULL,"-save",&flg);
75: if (flg) {
76: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
77: sprintf(filename,"local.%d",rank);
78: PetscViewerASCIIOpen(PETSC_COMM_SELF,filename,&viewer);
79: PetscViewerASCIIGetPointer(viewer,&file);
80: VecView(local,viewer);
81: fprintf(file,"Vector with correct ghost points\n");
82: VecView(local_copy,viewer);
83: PetscViewerDestroy(viewer);
84: }
86: VecAXPY(local_copy,-1.0,local);
87: VecNorm(local_copy,NORM_MAX,&work);
88: MPI_Allreduce(&work,&norm,1,MPIU_REAL,MPI_MAX,PETSC_COMM_WORLD);
89: PetscPrintf(PETSC_COMM_WORLD,"Norm of difference %G should be zero\n",norm);
90:
91: VecDestroy(local_copy);
92: VecDestroy(local);
93: VecDestroy(global);
94: DADestroy(da);
95: PetscFinalize();
96: return 0;
97: }