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

Enabling buffered I/O to stdout with Intel ifort compiler

ciaron
Beginner
2,895 Views

I've read the Intel docs about enabling buffered I/O with ifort (using -assume buffered_io or FORT_BUFFERED=true), and this works fine for output directly to files. However, we have large applications that are writing to stdout (e.g.write(*,*) or write(stdout,*)), which is redirected to a file. Neither of the buffering techniques work in this case.

Other than refactoring the code to write directly to files, is there a method to enable buffered I/O on stdout with ifort? This is enabled by default on, for example, gfortran.

We're using ifort 12.0 on SLES 11.

0 Kudos
1 Solution
Ron_Green
Moderator
2,895 Views

this feature has been implemented in Intel Fortran Composer XE 2013 SP1, aka version 14.0 of the compiler.

This must be explicitly asked for, with compiler option -assume buffered_stdout.  The default is -assume nobuffered_stdout.

Tells the Fortran run-time system to accumulate data for the standard output device in a buffer. When the buffer is full or the uses executes a FLUSH on OUTPUT_UNIT in intrinsic module ISO_FORTRAN_ENV, the data is displayed on the standard output unit.
Using buffered writes may be a more efficient in time and space but use assume nobuffered_stdout if you want data displayed immediately on the standard output device, like for an input prompt.
assume [no]buffered_stdout does not affect and is not affected by assume [no]buffered_io.

View solution in original post

0 Kudos
6 Replies
Ron_Green
Moderator
2,895 Views
There is no support for buffering IO for stdout. I can put in a feature request, but it will be for non-default behavior. Our runtime buffers on line boundaries by default. There is an obvious problem with making it default - users expect that write(*,*) statements for debug purposes come out in a timely manner. If you buffer them, you cannot rely on them for debug. also, for our cluster customers: if stdout is buffered and the distributed app is killed, it is very common to kill remote processes and destroy their buffers, hence NO output would come out. I will put in a feature request for a non-default way to enable buffering of stdout. I doubt we want to do this for stderr, as that information should definitely be delivered in near-real time. ron
0 Kudos
Ron_Green
Moderator
2,895 Views
Feature Request ID DPD200236607
0 Kudos
ciaron
Beginner
2,895 Views
Thanks very much! In the meantime, I'm investigating stdbuf and/or piping through a buffering program (like tee) as a workaround.
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,895 Views
Ronald, I found this on stackoverflow.com fpost_t pos; fgetpos(stdout, &pos); return (pos >= 0); As to if this alwasy works I cannot say. Jim Dempsey
0 Kudos
John_Damm_S_
Beginner
2,895 Views
We are facing the same problem and would like to know the status of the feature request. How about adopting the gfortran/g77 behavior where redirection to a file cause the I/O to be buffered? Best John
0 Kudos
Ron_Green
Moderator
2,896 Views

this feature has been implemented in Intel Fortran Composer XE 2013 SP1, aka version 14.0 of the compiler.

This must be explicitly asked for, with compiler option -assume buffered_stdout.  The default is -assume nobuffered_stdout.

Tells the Fortran run-time system to accumulate data for the standard output device in a buffer. When the buffer is full or the uses executes a FLUSH on OUTPUT_UNIT in intrinsic module ISO_FORTRAN_ENV, the data is displayed on the standard output unit.
Using buffered writes may be a more efficient in time and space but use assume nobuffered_stdout if you want data displayed immediately on the standard output device, like for an input prompt.
assume [no]buffered_stdout does not affect and is not affected by assume [no]buffered_io.

0 Kudos
Reply