xref: /petsc/src/mat/tests/ex255.c (revision a69119a591a03a9d906b29c0a4e9802e4d7c9795)
1 static char help[] = "Tests MatConvert from AIJ to MATIS with a block size greater than 1.\n";
2 
3 #include <petscmat.h>
4 int main(int argc, char **args) {
5   Mat         A, B;
6   char        file[PETSC_MAX_PATH_LEN];
7   PetscViewer fd;
8   PetscBool   flg, equal;
9 
10   PetscFunctionBeginUser;
11   PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
12 
13   /* Load an AIJ matrix */
14   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", file, sizeof(file), &flg));
15   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER, "Must indicate binary file with the -f option");
16   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd));
17   PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
18   PetscCall(MatSetFromOptions(A));
19   PetscCall(MatLoad(A, fd));
20 
21   /* Convert it to MATIS */
22   PetscCall(MatConvert(A, MATIS, MAT_INITIAL_MATRIX, &B));
23 
24   /* Check they are equal */
25   PetscCall(MatEqual(A, B, &equal));
26   PetscCheck(equal, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "A and B are not equal");
27 
28   PetscCall(MatDestroy(&A));
29   PetscCall(MatDestroy(&B));
30   PetscCall(PetscViewerDestroy(&fd));
31   PetscCall(PetscFinalize());
32 }
33 
34 /*TEST
35    test:
36      requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
37      args: -mat_type aij -matload_block_size {{1 2}} -f ${DATAFILESPATH}/matrices/smallbs2
38      output_file: output/empty.out
39 
40 TEST*/
41