Newsgroups: comp.parallel.pvm
From: bmanchek@ens-lyon.fr (Bob Manchek)
Subject: Re: problems getting stdout from spawned ta
Organization: Ecole Normale Superieure de Lyon
Date: 26 Oct 1994 09:56:14 GMT
Message-ID: <38l93u$sim@cri.ens-lyon.fr>

In article oaa@nuscc.nus.sg, nsrcchk@leonis.nus.sg (Heng Kek) writes:
> Gareth Evans# (gme@cpcw7.uea.ac.uk) wrote:
> 
> : I'm having trouble getting the stdout of a number of slave processes
> : spawned by a master.
> 
> : There is nothing in /tmp/pvml.<UID> and I tried a pvm_catchout( stdout ) but
> : still nothing.
> 
> I've had the same problems.  i.e. printf() statments in spawned
> slave processes produce nothing in /tmp/pvml.xxx.  But when I
> switched to 'fprintf(stderr,...)' then the stuff appears in the log
> file.  This is for pvm3.2.6.  I don't know if the same situation
> persists in pvm3.3
> 
> Would be grateful if an explanation can be posted here.

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 character '\n'
is encountered.  If the descriptor is a file, pipe, or socket,
however, stdio buffers up much more, like 4k bytes.

Thus their stdio libs 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).  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.

b

---
/ Robert Manchek                University of Tennessee     /
/                               Computer Science Department /
/ (615)974-8295                 Ayres Hall #104             /
/ manchek@CS.UTK.EDU.           Knoxville TN  37996-1301    /
/     http://www.netlib.org/utk/people/BobManchek.html      /



