I don't see printed output from tasks right away or at all

next up previous contents
Next: In what directory Up: Running and debugging Previous: Where does stuff

I don't see printed output from tasks right away or at all

The output from a spawned task goes through a pipe to the task's local pvmd, which routes it in a message to the output collector (the master pvmd, console or ancestor task that called pvm_catchout).

The C stdio library (fgets, printf, etc.) buffers input and output for efficiency whenever possible. That is, it tries to reduce the frequency of actual read or write system calls. It decides whether to buffer by looking at the underlying file descriptor of a stream. If the descriptor is for a tty, it buffers only a line at a time, that is, the buffer is flushed whenever the newline character is encountered. If the descriptor is a file, pipe, or socket, however, stdio buffers up much more, typically 4k bytes.

Thus their stdio libraries buffer more than a line before writing to the socket (because they don't know they're really talking to a human).

There are a few ways to see your output at the correct time. You can put: fflush(stdout)

after each printf() (or periodically in the program). Or, change the buffering mode of the stdout stream to line-oriented for the entire program by putting: setlinebuf(stdout)

near the top of the program. See the setlinebuf man page for more information.

Fortran users may encounter similar problems. Some Fortran libraries include a FLUSH subroutine, some don't; you'll have to figure that one out yourself.

Also, if the program is killed or doesn't exit cleanly, (in C, by calling pvm_exit and exit) any buffered output may be lost.

Bob Manchek
Fri Mar 3 15:08:11 EST 1995