Actual source code: ex206.c

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1: static char help[] = "Reads binary matrix - twice\n";

  3:  #include <petscmat.h>
  4: int main(int argc,char **args)
  5: {
  6:   Mat               A;
  7:   PetscViewer       fd;                        /* viewer */
  8:   char              file[PETSC_MAX_PATH_LEN];  /* input file name */
  9:   PetscErrorCode    ierr;
 10:   PetscBool         flg;

 12:   PetscInitialize(&argc,&args,(char*)0,help);

 14:   PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);
 15:   if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the -f option");

 17:   MatCreate(PETSC_COMM_WORLD,&A);
 18:   MatSetFromOptions(A);
 19:   PetscPrintf(PETSC_COMM_WORLD, "First MatLoad! \n");
 20:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 21:   MatLoad(A,fd);
 22:   PetscViewerDestroy(&fd);
 23:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

 25:   PetscOptionsGetString(NULL,NULL,"-f2",file,PETSC_MAX_PATH_LEN,&flg);
 26:   PetscPrintf(PETSC_COMM_WORLD, "Second MatLoad! \n");
 27:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 28:   MatLoad(A,fd);
 29:   PetscViewerDestroy(&fd);
 30:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

 32:   MatDestroy(&A);
 33:   PetscFinalize();
 34:   return ierr;
 35: }