Actual source code: ex173.c
petsc-3.8.4 2018-03-24
2: static char help[] = "Test MatrixMarket outputing.\n\n";
5: /*
6: Include "petscmat.h" so that we can use matrices.
7: automatically includes:
8: petscsys.h - base PETSc routines petscvec.h - vectors
9: petscmat.h - matrices
10: petscis.h - index sets petscviewer.h - viewers
11: */
12: #include <petscmat.h>
14: int main(int argc,char **args)
15: {
16: Mat A;
17: PetscViewer fd; /* viewer */
18: char file[PETSC_MAX_PATH_LEN]; /* input file name */
20: PetscBool flg;
21:
22: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
23: PetscOptionsGetString(NULL,NULL,"-f0",file,PETSC_MAX_PATH_LEN,&flg);
24: if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the -f0 option");
25: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
26: MatCreate(PETSC_COMM_WORLD,&A);
27: MatLoad(A,fd);
28: PetscViewerDestroy(&fd);
30: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATRIXMARKET);
31: MatView(A,PETSC_VIEWER_STDOUT_WORLD);
32: PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
33: MatDestroy(&A);
34: PetscFinalize();
35: return ierr;
36: }