Actual source code: ex173.c

  1: static char help[] = "Test MatrixMarket outputting.\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: */

 11: #include <petscmat.h>

 13: int main(int argc,char **args)
 14: {
 15:   Mat            A;
 16:   PetscViewer    fd;                        /* viewer */
 17:   char           file[PETSC_MAX_PATH_LEN];  /* input file name */
 18:   PetscBool      flg;

 20:   PetscInitialize(&argc,&args,(char*)0,help);
 21:   PetscOptionsGetString(NULL,NULL,"-f0",file,sizeof(file),&flg);
 23:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 24:   MatCreate(PETSC_COMM_WORLD,&A);
 25:   MatLoad(A,fd);
 26:   PetscViewerDestroy(&fd);

 28:   PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATRIXMARKET);
 29:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);
 30:   PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
 31:   MatDestroy(&A);
 32:   PetscFinalize();
 33:   return 0;
 34: }

 36: /*TEST

 38:    test:
 39:       args: -f0 ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64
 40:       requires: !complex double !defined(PETSC_USE_64BIT_INDICES)

 42: TEST*/