Actual source code: ex46.c
petsc-3.8.4 2018-03-24
2: static char help[] = "Tests late MatSetBlockSizes.\n\n";
4: #include <petscmat.h>
6: int main(int argc,char **args)
7: {
8: Mat A;
9: Vec x[4];
10: IS is;
11: ISLocalToGlobalMapping rmap,cmap;
12: PetscInt bs[4],l2gbs[4],rbs,cbs,l2grbs,l2gcbs,i;
13: PetscErrorCode ierr;
15: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
16: MatCreate(PETSC_COMM_WORLD,&A);
17: MatSetSizes(A,12,12,PETSC_DECIDE,PETSC_DECIDE);
18: MatSetType(A,MATAIJ);
19: ISCreateStride(PETSC_COMM_WORLD,12,0,1,&is);
20: ISLocalToGlobalMappingCreateIS(is,&rmap);
21: ISLocalToGlobalMappingSetBlockSize(rmap,2);
22: ISLocalToGlobalMappingCreateIS(is,&cmap);
23: ISLocalToGlobalMappingSetBlockSize(cmap,2);
25: MatSetLocalToGlobalMapping(A,rmap,cmap);
26: ISLocalToGlobalMappingDestroy(&rmap);
27: ISLocalToGlobalMappingDestroy(&cmap);
28: ISDestroy(&is);
29: MatSetUp(A);
31: MatCreateVecs(A,&x[1],&x[0]);
32: MatSetBlockSizes(A,6,3);
33: MatCreateVecs(A,&x[3],&x[2]);
34: for (i=0;i<4;i++) {
35: ISLocalToGlobalMapping l2g;
37: VecGetBlockSize(x[i],&bs[i]);
38: VecGetLocalToGlobalMapping(x[i],&l2g);
39: ISLocalToGlobalMappingGetBlockSize(l2g,&l2gbs[i]);
40: VecDestroy(&x[i]);
41: }
42: MatGetBlockSizes(A,&rbs,&cbs);
43: MatGetLocalToGlobalMapping(A,&rmap,&cmap);
44: ISLocalToGlobalMappingGetBlockSize(rmap,&l2grbs);
45: ISLocalToGlobalMappingGetBlockSize(cmap,&l2gcbs);
46: MatDestroy(&A);
47: PetscPrintf(PETSC_COMM_WORLD,"Mat Block sizes: %D %D (l2g %D %D)\n",rbs,cbs,l2grbs,l2gcbs);
48: PetscPrintf(PETSC_COMM_WORLD,"Vec Block sizes: %D %D (l2g %D %D)\n",bs[0],bs[1],l2gbs[0],l2gbs[1]);
49: PetscPrintf(PETSC_COMM_WORLD,"Vec Block sizes: %D %D (l2g %D %D)\n",bs[2],bs[3],l2gbs[2],l2gbs[3]);
50: PetscFinalize();
51: return ierr;
52: }