Read FIFO blocked with gfortran (vs ifort)

Tobias Burnus tobias.burnus@physik.fu-berlin.de
Thu Sep 30 08:14:00 GMT 2010


On Tue, Sep 28, 2010 at 12:18:20PM +0200, Giraudon Cyril wrote:
>    and when i compile with gfortran : gfortran -o controlspice
>      controlspice.f90
>    I have to stop the run cause it is blocked.

I quickly tried. Result: It stops at the same position with pathscale
and pgi as with gfortran; if I swap the order of

    call read_string_message(string_message, 8)
    call write_string_message("set noaskquit")

it also shows the 8 lines with gfortran (but stops later).


> The issue occurs while the reading statement.
> Can the "read buffer" be full ?

My feeling is that the reason is the opposite. gfortran tries to read
more data than it is available and thus waits for it to become available.

If you somewhere else "echo "?" >> input.fifo" a help window pops up
and more data shows up.


Addition information:
a) Using GFORTRAN_UNBUFFERED_ALL=y it stops with
...
  7/  8 >                                                      ******

b) Without GFORTRAN_UNBUFFERED_ALL= it stops already with
  6/  8 >             ** Creation Date: Wed Sep 29 15:33:01 CEST 2010

  if (isatty (s->fd) || options.all_unbuffered
      ||(options.unbuffered_preconnected && 
         (s->fd == STDIN_FILENO 
          || s->fd == STDOUT_FILENO 
          || s->fd == STDERR_FILENO)))
    raw_init (s);
  else
    buf_init (s);

I wonder whether one should not also add "!is_seekable(s->fd)" to those
items which are by default unbuffert.


For GFORTRAN_UNBUFFERED_ALL=N the backtrace look as follows, where
raw_read calls POSIX read.

#0  0x00000038fa8c5ff0 in __read_nocancel () from /lib64/libc.so.6
#1  0x00002aaaaab6f9b9 in raw_read (s=0x6067d0, buf=<value optimized out>, nbyte=<value optimized out>)
    at ../../../gcc-trunk-source/gcc/libgfortran/io/unix.c:274
#2  buf_read (s=0x6067d0, buf=<value optimized out>, nbyte=<value optimized out>)
    at ../../../gcc-trunk-source/gcc/libgfortran/io/unix.c:470

raw_read calls POSIX's read. From POSIX (1003.1:2003):

"      ssize_t read(int fildes, void *buf, size_t nbyte);

DESCRIPTION
       The  read()  function  shall attempt to read nbyte bytes from the
       file associated with the open file descriptor, fildes,  into  the
       buffer  pointed  to  by  buf. The behavior of multiple concurrent
       reads on the same pipe, FIFO, or terminal device is  unspecified.
[...]
                            The value returned may be less than nbyte if
       the number of bytes left in the file is less than nbyte,  if  the
       read()  request  was interrupted by a signal, or if the file is a
       pipe or FIFO or special file and has fewer than nbyte bytes imme-
       diately  available for reading. For example, a read() from a file
       associated with a terminal may return one typed line of data."


Thus, in principle it should work - at least with
GFORTRAN_UNBUFFERED_ALL=Y - even though it does not.

Tobias



More information about the Fortran mailing list