[petsc-users] check status of reading matrix from a file

Smith, Barry F. bsmith at mcs.anl.gov
Tue Feb 13 11:31:56 CST 2018


  Hmm, it shouldn't hang but should crash if the file does not exist.

  If you want the code to continue running with or without the file you can use PetscTestFile() to see if the file exists
and do something else if it does not exist.

   Barry


> On Feb 13, 2018, at 11:10 AM, Michael Povolotskyi <mpovolot at purdue.edu> wrote:
> 
> Dear Petsc developers,
> 
> I'm reading a matrix from a file like this:
> 
> PetscViewer viewer;
> PetscErrorCode ierr;
> 
> MatCreate(comm,&matrix);
> 
> MatSetType(matrix,MATDENSE);
> 
> ierr = PetscViewerBinaryOpen(comm,file_name,FILE_MODE_READ,&viewer);
> ierr = MatLoad(matrix,viewer);
> 
> 
> Sometimes the file that is needed is not present and the code execution becomes frozen.
> 
> Is it possible to catch this situation looking at the ierr variable?
> 
> Thank you,
> 
> Michael.
> 



More information about the petsc-users mailing list