Actual source code: ex173.c

petsc-3.10.5 2019-03-28
Report Typos and Errors
  1: static char help[] = "Test MatrixMarket outputing.\n\n";

  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: /*T
 11:    TODO: Need to determine if deprecated
 12: T*/

 14:  #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;

 24:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 25:   PetscOptionsGetString(NULL,NULL,"-f0",file,PETSC_MAX_PATH_LEN,&flg);
 26:   if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the -f0 option");
 27:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 28:   MatCreate(PETSC_COMM_WORLD,&A);
 29:   MatLoad(A,fd);
 30:   PetscViewerDestroy(&fd);

 32:   PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATRIXMARKET);
 33:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);
 34:   PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
 35:   MatDestroy(&A);
 36:   PetscFinalize();
 37:   return ierr;
 38: }

 40: /*TEST

 42:    test:
 43:       args: -f0 ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64
 44:       requires: !complex double !define(PETSC_USE_64BIT_INDICES)

 46: TEST*/