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