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

Fastest way to read/write binary data?

david_sallngc_com
1,911 Views
Hi!

I am reading/writing large datasets of double precision real data and single precision integer data and would like to know if there is a way I can speed up the I/O. I do my I/O using binary data and am using Intel FORTRAN 11.1. In particular, I open my files by,

open(unit=fid, file = 'foo.dat', form = 'unformatted', access = 'stream')

I READ and WRITE my data as,

do i = 1,N
read(fid) x(i)
write(fid) x(i)
end do

Is there a way to use OpenMP to help speed up the I/O?

Thank you very much for your help.

Sincerely,

David
0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,911 Views
You're reading an element at a time, which has a lot of overhead. Can you read a whole array at a time, process it and then write a whole array?
0 Kudos
david_sallngc_com
1,911 Views
Hi Steve!

Yes, I can write an entire vector at one time. It is a very large vector though. Is there a way I can check, apriori, via some code, to make sure I have enoughmemory to write it in one chunk or is this not even a concern?

Is is possible to use OpenMP in some way to write different chunks of data to a file at the same time?

Is writing entire vectors at one time the fastest I can do?

Thanks Steve.

David
0 Kudos
Steven_L_Intel1
Employee
1,911 Views
Since you're using ACCESS='STREAM' you can decide how much to read at a time. If you can overlap the reading, computation and writing you might want to look into using ASYCHRONOUS='YES' option on opening the file and doing the I/O. Read more about that in the documentation, though I'd advise you to use version 12 (Composer XE 2011) for best results.

It is not clear to me that OpenMP will help you here, but there are many experienced parallel applications programmers in this forum who I am sure will offer opinions.

How do you know that it's the I/O that is the limiting factor?
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,911 Views
>>Is is possible to use OpenMP in some way to write different chunks of data to a file at the same time?

real :: YourData(BigSize)
integer, volatile :: ElementsInsertedIntoBuffer
logical :: InsertionsFinished
integer, volatile :: LastElementWritten
logical :: WriteError
ElementsInsertedIntoBuffer = 0
InsertionsFinished = .false.
LastElementWritten = 0
WriteError = .false.

!$omp parallel sections
do while((.not. InsertionsFinished) .and. (.not. WriteError))
InsertionsFinished = AppendDataToBuffer(YourData, ElementsInsertedIntoBuffer)
end do
!$omp section
do while((.not. InsertionsFinished) .or. (ElementsInsertedIntoBuffer .gt. LastElementWritten))
if(ElementsInsertedIntoBuffer .gt. LastElementWritten) then
WriteError= WriteDataFromBuffer(YourData, LastElementWritten)
if(WriteError) exit
else
sleepqq(100)
endif
end do
!$omp end parallel sections

Something like that will do. I will let you write the functions.

Note, you can also use two data arrays as a double buffer or use a smaller large array as a circular buffer (with logic to avoid overrunning the writes).

A similar thing can be done for reading the data.

Note, the writes in your WriteDataFromBuffer would be normal writes.

Jim Dempsey
0 Kudos
david_sallngc_com
1,911 Views
Dear Jim and Steve!

Thank you both very much for your suggestions. Sounds fantastic.

Now for some fun coding!!

Sincerely,

David
0 Kudos
Reply