[petsc-users] PetscBinaryRead fails
Smith, Barry F.
bsmith at mcs.anl.gov
Mon Feb 18 22:06:16 CST 2019
I don't know how you got your _test file but it is the wrong size
$ ls -l _test
-rw-r--r--@ 1 barrysmith staff 6 Feb 18 21:25 _test
~/Src/petsc/test-dir (maint=) arch-basic
it only has 6 bytes but to hold a PETSC_SCALAR (when PetscScalar is real) it should have 8 bytes. For example the code
PetscViewer viewer;
PetscScalar v;
int fd;
PetscViewerBinaryOpen(PETSC_COMM_WORLD, "joe", FILE_MODE_WRITE, &viewer);
PetscViewerBinaryGetDescriptor(viewer, &fd);
PetscBinaryWrite(fd, &value, 1, PETSC_SCALAR,PETSC_FALSE);
PetscViewerDestroy(&viewer);
produces a file with 8 bytes in it
$ ls -l joe
-rw-r--r-- 1 barrysmith staff 8 Feb 18 22:03 joe
which can be read in by your program.
> On Feb 18, 2019, at 9:23 PM, Yuyun Yang <yyang85 at stanford.edu> wrote:
>
> I used FILE_MODE_READ. Please see attached file (the function is part of another file therefore all the other include statements; I've extracted it here). The test file only contains one number. My directory is hard-coded into the main function.
>
> Thanks a lot!
> Yuyun
>
> -----Original Message-----
> From: Smith, Barry F. <bsmith at mcs.anl.gov>
> Sent: Monday, February 18, 2019 6:41 PM
> To: Yuyun Yang <yyang85 at stanford.edu>
> Cc: petsc-users at mcs.anl.gov
> Subject: Re: [petsc-users] PetscBinaryRead fails
>
>
> Send program and data file if you cannot get it to work.
>
>
>> On Feb 18, 2019, at 8:08 PM, Yuyun Yang via petsc-users <petsc-users at mcs.anl.gov> wrote:
>>
>> Hello,
>>
>> I am writing a very simple function just to read in a single value from an input file (which also just contains one single scalar value). Using PetscBinaryRead(fd, &value, 1, PETSC_SCALAR) gives me the following error. Could you help me figure out why?
>>
>> [0]PETSC ERROR: --------------------- Error Message
>> --------------------------------------------------------------
>> [0]PETSC ERROR: Read from file failed
>> [0]PETSC ERROR: Read past end of file
>> [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.10.3, unknown [0]PETSC ERROR:
>> ./output on a arch-linux2-c-debug named DESKTOP-02K82L1.stanford.edu
>> by yyy910805 Mon Feb 18 17:58:30 2019 [0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-shared-libraries=1 --download-hdf5 --download-metis --download-parmetis --download-hypre --download-superlu --download-mumps --download-scalapack --download-mpich --download-mpich-configure-arguments="--enable-error-messages=all --enable-g"
>> [0]PETSC ERROR: #1 PetscBinaryRead() line 276 in
>> /home/yyy910805/petsc/src/sys/fileio/sysio.c
>> 0.000000
>>
>> Thanks a lot!
>> Yuyun
>
> <testCheckpointLoadVal.cpp><_test>
More information about the petsc-users
mailing list