问题
I've read the Intel docs about enabling buffered I/O with ifort (using -assume buffered_io
or FORT_BUFFERED=true
), and this works 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.
Update: Thanks for the comments. I'm investigating stdbuf and/or piping through a buffering program (like tee) as a workaround. As yet, I haven't been able to make a measurable difference.
Update 2:
I've tried some experiments with Douglas's suggestion, piping through another program. tee and cat both buffer, in face the buffering seems to done by the pipe itself at about 8K. However, the overhead of the original write() calls, plus the pipe, plus the system calls of the piping program (tee, cat etc.) are too high to make this a workable solution.
来源:https://stackoverflow.com/questions/12511620/enable-buffered-i-o-to-stdout-with-intel-ifort-compiler