Enabling buffered I/O to stdout with Intel ifort compiler

Enabling buffered I/O to stdout with Intel ifort compiler

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.

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Feature Request ID DPD200236607

Thanks very much! In the meantime, I'm investigating stdbuf and/or piping through a buffering program (like tee) as a workaround.

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

www.quickthreadprogramming.com

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

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.

Leave a Comment

Please sign in to add a comment. Not a member? Join today