Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

ifort: problem reading unformatted sequential files

gavpol
Beginner
1,337 Views
Hi. I've written some f95 code to do a taskwhere speed of execution is important. I've been using a free compiler (gfortran) but thought I'd try Intel's, anticipating that it would be faster. I need to read hundreds of image files, to do a tomographic reconstruction, one after another. Each file consists of a 100 byte header and 1024x1024 2-byte integers. Formatted access has been painfully slow in the past, when I've tried it, so I have used the following ugly fix - pretending the images are unformatted file:

INTEGER(KIND=2), DIMENSION(N) :: PV
CHARACTER(LEN=96) :: HEADER

OPEN(UNIT=1, FILE=VIEWNAME, STATUS="OLD",FORM="UNFORMATTED",ACTION="READ")
READ(UNIT=1) HEADER,PV
CLOSE(UNIT=1,STATUS="KEEP")


By defining the HEADER length to be 4 bytes short, I account for the 4-byte bookend I expect fortran to introduce.The problem is: this works fine in gfortran but ifort has a fit when it tries to read the files (severe error (39) I think). My questions are:

(1) Is there a way to get this to work with ifort?
(2) Or can someone suggest a better way to read my files with comparable speed.

Any help would be much appreciated.

Thanks

G.
0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,337 Views
Are you aware that there is a 4-byte "bookend" on both ends of the record? This should be the same as gfortran.

I would recommend opening the file as ACCESS='STREAM' (keep the other things you have in the OPEN.) Then when you do unformatted reads, you'll read ONLY data and there will not be any "bookends". This is a standard Fortran 2003 feature. You'll want to redefine the length of HEADER to be *100.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,337 Views

If you want maximum performance using IVF consider using Binary Sequential files (must be written in binary sequential to be read in binary sequential).

If you use a user defined type containing your 100 byte record plus the 1024x1024 2 byte integers pluspadd data to next 512 byte addressyou could potentially read this with 1 I/O operation directly into the user defined type variable. Cann't say if IVF would bypass reading to an internal I/O buffer when reading disk block sized and aligned binary data.

Jim
0 Kudos
gavpol
Beginner
1,337 Views
Hey.

Thanks alot! The stream i/o works a treat. Which has made my day. Didn't know about that.

Thecode works. And it runs very fast.

G.
0 Kudos
Reply