Actual source code: ex87.c
petsc-3.9.4 2018-09-11
2: static char help[] = "Tests MatCreateSubMatrices() for SBAIJ matrices\n\n";
4: #include <petscmat.h>
6: int main(int argc,char **args)
7: {
8: Mat BAIJ,SBAIJ,*subBAIJ,*subSBAIJ;
9: PetscViewer viewer;
10: char file[PETSC_MAX_PATH_LEN];
11: PetscBool flg;
13: PetscInt n = 2,issize,M,N;
14: PetscMPIInt rank;
15: IS isrow,iscol,irow[n],icol[n];
17: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
18: PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);
19: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);
21: MatCreate(PETSC_COMM_WORLD,&BAIJ);
22: MatSetType(BAIJ,MATMPIBAIJ);
23: MatLoad(BAIJ,viewer);
24: PetscViewerDestroy(&viewer);
26: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);
27: MatCreate(PETSC_COMM_WORLD,&SBAIJ);
28: MatSetType(SBAIJ,MATMPISBAIJ);
29: MatLoad(SBAIJ,viewer);
30: PetscViewerDestroy(&viewer);
32: MatGetSize(BAIJ,&M,&N);
33: issize = M/4;
34: ISCreateStride(PETSC_COMM_SELF,issize,0,1,&isrow);
35: irow[0] = irow[1] = isrow;
36: issize = N/2;
37: ISCreateStride(PETSC_COMM_SELF,issize,0,1,&iscol);
38: icol[0] = icol[1] = iscol;
39: MatCreateSubMatrices(BAIJ,n,irow,icol,MAT_INITIAL_MATRIX,&subBAIJ);
40: MatCreateSubMatrices(BAIJ,n,irow,icol,MAT_REUSE_MATRIX,&subBAIJ);
42: /* irow and icol must be same for SBAIJ matrices! */
43: icol[0] = icol[1] = isrow;
44: MatCreateSubMatrices(SBAIJ,n,irow,icol,MAT_INITIAL_MATRIX,&subSBAIJ);
45: MatCreateSubMatrices(SBAIJ,n,irow,icol,MAT_REUSE_MATRIX,&subSBAIJ);
47: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
48: if (!rank) {
49: MatView(subBAIJ[0],PETSC_VIEWER_STDOUT_SELF);
50: MatView(subSBAIJ[0],PETSC_VIEWER_STDOUT_SELF);
51: }
53: /* Free data structures */
54: ISDestroy(&isrow);
55: ISDestroy(&iscol);
56: MatDestroySubMatrices(n,&subBAIJ);
57: MatDestroySubMatrices(n,&subSBAIJ);
58: MatDestroy(&BAIJ);
59: MatDestroy(&SBAIJ);
61: PetscFinalize();
62: return ierr;
63: }