Actual source code: ex22.c
petsc-dev 2014-02-02
2: static char help[] = "Tests MatSetValuesBlockedStencil() in 3d.\n\n";
4: #include <petscmat.h>
5: #include <petscdmda.h>
9: int main(int argc,char **argv)
10: {
11: PetscInt M = 3,N = 4,P = 2,s = 1,w = 2,i, m = PETSC_DECIDE,n = PETSC_DECIDE,p = PETSC_DECIDE;
12: PetscErrorCode ierr;
13: DM da;
14: Mat mat;
15: DMDAStencilType stencil_type = DMDA_STENCIL_BOX;
16: PetscBool flg = PETSC_FALSE;
17: MatStencil idx[2],idy[2];
18: PetscScalar *values;
20: PetscInitialize(&argc,&argv,(char*)0,help);
22: /* Read options */
23: PetscOptionsGetInt(NULL,"-M",&M,NULL);
24: PetscOptionsGetInt(NULL,"-N",&N,NULL);
25: PetscOptionsGetInt(NULL,"-P",&P,NULL);
26: PetscOptionsGetInt(NULL,"-m",&m,NULL);
27: PetscOptionsGetInt(NULL,"-n",&n,NULL);
28: PetscOptionsGetInt(NULL,"-p",&p,NULL);
29: PetscOptionsGetInt(NULL,"-s",&s,NULL);
30: PetscOptionsGetInt(NULL,"-w",&w,NULL);
31: PetscOptionsGetBool(NULL,"-star",&flg,NULL);
32: if (flg) stencil_type = DMDA_STENCIL_STAR;
34: /* Create distributed array and get vectors */
35: DMDACreate3d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,stencil_type,M,N,P,m,n,p,w,s,
36: 0,0,0,&da);
38: DMSetMatType(da,MATMPIBAIJ);
39: DMCreateMatrix(da,&mat);
41: idx[0].i = 1; idx[0].j = 1; idx[0].k = 0;
42: idx[1].i = 2; idx[1].j = 1; idx[1].k = 0;
43: idy[0].i = 1; idy[0].j = 2; idy[0].k = 0;
44: idy[1].i = 2; idy[1].j = 2; idy[1].k = 0;
45: PetscMalloc1(2*2*w*w,&values);
46: for (i=0; i<2*2*w*w; i++) values[i] = i;
47: MatSetValuesBlockedStencil(mat,2,idx,2,idy,values,INSERT_VALUES);
48: MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY);
49: MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY);
51: /* Free memory */
52: PetscFree(values);
53: MatDestroy(&mat);
54: DMDestroy(&da);
55: PetscFinalize();
56: return 0;
57: }