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