Actual source code: ex173.c
petsc-3.6.1 2015-08-06
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>
16: int main(int argc,char **args)
17: {
18: Mat A;
19: PetscViewer fd; /* viewer */
20: char file[PETSC_MAX_PATH_LEN]; /* input file name */
22: PetscBool flg;
23:
24: PetscInitialize(&argc,&args,(char*)0,help);
26: PetscOptionsGetString(NULL,"-f0",file,PETSC_MAX_PATH_LEN,&flg);
27: if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the -f0 option");
28: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
29: MatCreate(PETSC_COMM_WORLD,&A);
30: MatLoad(A,fd);
31: PetscViewerDestroy(&fd);
33: PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATRIXMARKET);
34: MatView(A,PETSC_VIEWER_STDOUT_WORLD);
35: MatDestroy(&A);
36: PetscFinalize();
37: return 0;
38: }