1 /* tests MatSeqSBAIJSetPreallocationCSR() and MatMPISBAIJSetPreallocationCSR() */
2
3 #include <petsc.h>
4
main(int argc,char ** args)5 int main(int argc, char **args)
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 Mat ssbaij, msbaij;
11 PetscBool v2 = PETSC_FALSE;
12
13 PetscFunctionBeginUser;
14 PetscCall(PetscInitialize(&argc, &args, NULL, NULL));
15 PetscCall(PetscOptionsGetBool(NULL, NULL, "-v2", &v2, NULL));
16
17 PetscCall(MatCreate(PETSC_COMM_SELF, &ssbaij));
18 PetscCall(MatCreate(PETSC_COMM_SELF, &msbaij));
19 if (!v2) {
20 PetscCall(MatSetType(ssbaij, MATSEQSBAIJ));
21 PetscCall(MatSetType(msbaij, MATMPISBAIJ));
22 }
23 PetscCall(MatSetBlockSize(ssbaij, 2));
24 PetscCall(MatSetSizes(ssbaij, 4, 4, 4, 4));
25 PetscCall(MatSetBlockSize(msbaij, 2));
26 PetscCall(MatSetSizes(msbaij, 4, 4, 4, 4));
27 if (v2) {
28 PetscCall(MatSetUp(ssbaij));
29 PetscCall(MatSetUp(msbaij));
30 PetscCall(MatSetType(ssbaij, MATSEQSBAIJ));
31 PetscCall(MatSetType(msbaij, MATMPISBAIJ));
32 }
33 PetscCall(MatSeqSBAIJSetPreallocationCSR(ssbaij, 2, ia, ja, c));
34 PetscCall(MatMPISBAIJSetPreallocationCSR(msbaij, 2, ia, ja, c));
35 PetscCall(MatView(ssbaij, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)));
36 PetscCall(MatView(msbaij, PETSC_VIEWER_STDOUT_(PETSC_COMM_SELF)));
37 PetscCall(MatDestroy(&ssbaij));
38 PetscCall(MatDestroy(&msbaij));
39 PetscCall(PetscFinalize());
40 return 0;
41 }
42
43 /*TEST
44
45 test:
46 filter: sed "s?\.??g"
47
48 test:
49 suffix: 2
50 filter: sed "s?\.??g"
51 args : -v2
52 output_file: output/ex232_1.out
53
54 TEST*/
55