xref: /petsc/src/mat/tests/ex220.c (revision 2ff79c18c26c94ed8cb599682f680f231dca6444)
1 #include <petscmat.h>
2 
3 static char help[PETSC_MAX_PATH_LEN] = "Tests MatLoad() with MatCreateDense() for memory leak ";
4 
5 int main(int argc, char **argv)
6 {
7   PetscViewer viewer;
8   Mat         A;
9   char        filename[PETSC_MAX_PATH_LEN];
10   PetscBool   flg;
11 
12   PetscFunctionBeginUser;
13   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
14   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg));
15   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT, "Must indicate a filename for input with the -f option");
16 
17   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, filename, FILE_MODE_READ, &viewer));
18   PetscCall(MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, 36, 36, NULL, &A));
19   PetscCall(MatLoad(A, viewer));
20   PetscCall(PetscViewerDestroy(&viewer));
21   PetscCall(MatDestroy(&A));
22   PetscCall(PetscFinalize());
23   return 0;
24 }
25 
26 /*TEST
27 
28      test:
29        requires: double !complex !defined(PETSC_USE_64BIT_INDICES) datafilespath
30        args: -f ${DATAFILESPATH}/matrices/small
31        output_file: output/empty.out
32 
33 TEST*/
34