Actual source code: ex233.c
petsc-3.12.5 2020-03-29
1: static char help[] = "Tests MatMPI{AIJ,BAIJ,SBAIJ}SetPreallocationCSR\n\n";
3: #include <petscmat.h>
5: int main(int argc,char **argv)
6: {
8: PetscInt ia[3]={0,2,4};
9: PetscInt ja[4]={0,1,0,1};
10: PetscScalar c[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
11: PetscInt ia2[5]={0,4,8,12,16};
12: PetscInt ja2[16]={0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
13: PetscScalar c2[16]={0,1,4,5,2,3,6,7,8,9,12,13,10,11,14,15};
14: PetscMPIInt size,rank;
15: Mat ssbaij;
16: PetscBool rect = PETSC_FALSE;
18: PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
19: MPI_Comm_size(PETSC_COMM_WORLD,&size);
20: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
21: if (size < 2) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"This is an example with more then one processors");
22: if (rank) {
23: PetscInt i;
24: for (i = 0; i < 3; i++) ia[i] = 0;
25: for (i = 0; i < 5; i++) ia2[i] = 0;
26: }
27: PetscOptionsGetBool(NULL,NULL,"-rect",&rect,NULL);
28: MatCreate(PETSC_COMM_WORLD,&ssbaij);
29: MatSetBlockSize(ssbaij,2);
30: if (rect) {
31: MatSetType(ssbaij,MATMPIBAIJ);
32: MatSetSizes(ssbaij,4,6,PETSC_DECIDE,PETSC_DECIDE);
33: } else {
34: MatSetType(ssbaij,MATMPISBAIJ);
35: MatSetSizes(ssbaij,4,4,PETSC_DECIDE,PETSC_DECIDE);
36: }
37: MatSetFromOptions(ssbaij);
38: MatMPIAIJSetPreallocationCSR(ssbaij,ia2,ja2,c2);
39: MatMPIBAIJSetPreallocationCSR(ssbaij,2,ia,ja,c);
40: MatMPISBAIJSetPreallocationCSR(ssbaij,2,ia,ja,c);
41: MatViewFromOptions(ssbaij,NULL,"-view");
42: MatDestroy(&ssbaij);
43: PetscFinalize();
44: return ierr;
45: }
47: /*TEST
49: test:
50: filter: grep -v type | sed -e "s/\.//g"
51: suffix: aijbaij_csr
52: nsize: 2
53: args: -mat_type {{aij baij}} -view -rect {{0 1}}
55: test:
56: filter: sed -e "s/\.//g"
57: suffix: sbaij_csr
58: nsize: 2
59: args: -mat_type sbaij -view -rect {{0 1}}
61: TEST*/