xref: /petsc/src/mat/tests/ex173.c (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
1 static char help[] = "Test MatrixMarket outputting.\n\n";
2 
3 /*
4   Include "petscmat.h" so that we can use matrices.
5   automatically includes:
6      petscsys.h    - base PETSc routines   petscvec.h    - vectors
7      petscmat.h    - matrices
8      petscis.h     - index sets            petscviewer.h - viewers
9 */
10 
11 #include <petscmat.h>
12 
13 int main(int argc, char **args) {
14   Mat         A;
15   PetscViewer fd;                       /* viewer */
16   char        file[PETSC_MAX_PATH_LEN]; /* input file name */
17   PetscBool   flg;
18 
19   PetscFunctionBeginUser;
20   PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
21   PetscCall(PetscOptionsGetString(NULL, NULL, "-f0", file, sizeof(file), &flg));
22   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER, "Must indicate binary file with the -f0 option");
23   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd));
24   PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
25   PetscCall(MatLoad(A, fd));
26   PetscCall(PetscViewerDestroy(&fd));
27 
28   PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_MATRIXMARKET));
29   PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD));
30   PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
31   PetscCall(MatDestroy(&A));
32   PetscCall(PetscFinalize());
33   return 0;
34 }
35 
36 /*TEST
37 
38    test:
39       args: -f0 ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64
40       requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
41 
42 TEST*/
43