Actual source code: ex234.c
1: static char help[] = "Basic test of various routines with SBAIJ matrices\n\n";
3: #include <petscmat.h>
5: int main(int argc,char **argv)
6: {
7: PetscInt ia[3]={0,2,4};
8: PetscInt ja[4]={0,1,0,1};
9: PetscScalar c[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
10: PetscMPIInt size;
11: Mat ssbaij,msbaij;
12: Vec x,y;
14: PetscInitialize(&argc,&argv,NULL,help);
15: MPI_Comm_size(PETSC_COMM_WORLD,&size);
17: MatCreate(PETSC_COMM_SELF,&ssbaij);
18: MatSetType(ssbaij,MATSEQSBAIJ);
19: MatSetBlockSize(ssbaij,2);
20: MatSetSizes(ssbaij,4,8,4,8);
21: MatSeqSBAIJSetPreallocationCSR(ssbaij,2,ia,ja,c);
22: MatCreateMPIMatConcatenateSeqMat(PETSC_COMM_WORLD,ssbaij,PETSC_DECIDE,MAT_INITIAL_MATRIX,&msbaij);
23: MatView(msbaij,PETSC_VIEWER_STDOUT_WORLD);
24: MatDestroy(&msbaij);
25: MatCreateMPIMatConcatenateSeqMat(PETSC_COMM_WORLD,ssbaij,4,MAT_INITIAL_MATRIX,&msbaij);
26: MatView(msbaij,PETSC_VIEWER_STDOUT_WORLD);
27: MatCreateVecs(msbaij,&x,&y);
28: VecSet(x,1);
29: MatMult(msbaij,x,y);
30: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
31: MatMultAdd(msbaij,x,x,y);
32: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
33: MatGetDiagonal(msbaij,y);
34: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
35: VecDestroy(&x);
36: VecDestroy(&y);
37: MatDestroy(&msbaij);
38: MatDestroy(&ssbaij);
39: PetscFinalize();
40: return 0;
41: }
43: /*TEST
45: test:
46: nsize: 2
47: filter: sed "s?\.??g"
49: TEST*/