[petsc-users] reading petsc binary vec in python.

Ethan Coon ecoon at lanl.gov
Mon Jul 18 18:28:35 CDT 2011


Hi Ata,

Can you tell me what version of numpy you're using?  In some older
versions of numpy, a "fromfile" called on a file with no data left to
read did not error, but instead returned an empty list.  This
implementation, since it doesn't know how many objects are in the file,
tries to read objects until it gets an error saying the file is empty.
Try something for me:

change line 119 of PetscBinaryRead.py to read:

except MemoryError, IndexError:

Does that fix it?  

Thanks,

Ethan


On Mon, 2011-07-18 at 17:56 -0500, Ataollah Mesgarnejad wrote:
> Thanks Ethan,
> 
> I did as you said but when I try to read the file using:
> 
> petsc_objs = PetscBinaryRead.readBinaryFile('V-018.bin')
> 
> I get the following error:
> 
> Traceback (most recent call last):
>   File "./petscvec.py", line 4, in <module>
>     petsc_objs = PetscBinaryRead.readBinaryFile('V-018.bin')
>   File "/Users/ataollahmesgarnejad/Software/petsc-3.1/bin/python/PetscBinaryRead.py", line 118, in readBinaryFile
>     header = np.fromfile(fid, dtype=IntType, count=1)[0]
> IndexError: index out of bounds
> 
> Which is peculiar since when I try to read the header myself using:
> 
> header=numpy.fromfile('V-018.bin',dtype='>i4',count=1) 
> print header[0]
> 
> I get:
> 
> 1211214
> 
> which is a Vec identifier.
> 
> Any thoughts on what goes wrong?
> 
> Best,
> Ata

-- 
------------------------------------
Ethan Coon
Post-Doctoral Researcher
Applied Mathematics - T-5
Los Alamos National Laboratory
505-665-8289

http://www.ldeo.columbia.edu/~ecoon/
------------------------------------



More information about the petsc-users mailing list