Actual source code: ex23.c
2: static char help[] = "Tests VecView()/VecLoad() for DA vectors (this tests DAGlobalToNatural()).\n\n";
4: #include petscda.h
5: #include petscsys.h
9: int main(int argc,char **argv)
10: {
11: PetscMPIInt size;
12: PetscInt N = 6,m=PETSC_DECIDE,n=PETSC_DECIDE,p=PETSC_DECIDE,M=8,dof=1,stencil_width=1,P=5,pt = 0,st = 0;
14: PetscTruth flg2,flg3;
15: DAPeriodicType periodic = DA_NONPERIODIC;
16: DAStencilType stencil_type = DA_STENCIL_STAR;
17: DA da;
18: Vec global1,global2;
19: PetscScalar mone = -1.0;
20: PetscReal norm;
21: PetscViewer viewer;
22: PetscRandom rdm;
24: PetscInitialize(&argc,&argv,(char*)0,help);
26: PetscOptionsGetInt(PETSC_NULL,"-M",&M,PETSC_NULL);
27: PetscOptionsGetInt(PETSC_NULL,"-N",&N,PETSC_NULL);
28: PetscOptionsGetInt(PETSC_NULL,"-P",&P,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,"-1d",&flg2);
37: PetscOptionsHasName(PETSC_NULL,"-2d",&flg2);
38: PetscOptionsHasName(PETSC_NULL,"-3d",&flg3);
39: if (flg2) {
40: DACreate2d(PETSC_COMM_WORLD,periodic,stencil_type,M,N,m,n,dof,stencil_width,0,0,&da);
41: } else if (flg3) {
42: DACreate3d(PETSC_COMM_WORLD,periodic,stencil_type,M,N,P,m,n,p,dof,stencil_width,0,0,0,&da);
43: }
44: else {
45: DACreate1d(PETSC_COMM_WORLD,periodic,M,dof,stencil_width,PETSC_NULL,&da);
46: }
48: DACreateGlobalVector(da,&global1);
49: PetscRandomCreate(PETSC_COMM_WORLD,RANDOM_DEFAULT,&rdm);
50: VecSetRandom(global1,rdm);
51: PetscRandomDestroy(rdm);
53: DACreateGlobalVector(da,&global2);
55: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"temp",FILE_MODE_WRITE,&viewer);
56: VecView(global1,viewer);
57: PetscViewerDestroy(viewer);
59: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"temp",FILE_MODE_READ,&viewer);
60: VecLoadIntoVector(viewer,global2);
61: PetscViewerDestroy(viewer);
63: VecAXPY(global2,mone,global1);
64: VecNorm(global2,NORM_MAX,&norm);
65: if (norm != 0.0) {
66: MPI_Comm_size(PETSC_COMM_WORLD,&size);
67: PetscPrintf(PETSC_COMM_WORLD,"Norm of difference %G should be zero\n",norm);
68: PetscPrintf(PETSC_COMM_WORLD," Number of processors %d\n",size);
69: PetscPrintf(PETSC_COMM_WORLD," M,N,P,dof %D %D %D %D\n",M,N,P,dof);
70: PetscPrintf(PETSC_COMM_WORLD," stencil_width %D stencil_type %d periodic %d\n",stencil_width,(int)stencil_type,(int)periodic);
71: PetscPrintf(PETSC_COMM_WORLD," dimension %d\n",1 + (int) flg2 + (int) flg3);
72: }
73:
74: DADestroy(da);
75: VecDestroy(global1);
76: VecDestroy(global2);
77: PetscFinalize();
78: return 0;
79: }