There is unfortunately a great deal of black magic and voodoo involved
in sending the stdout/stderr from all processes in MPI_COMM_WORLD to
mpirun; we didn't make this mechanism available to MPI processes.
One very non-portable mechanism that you may find helpful, however, is
the lam_debug() API. See share/include/lamdebug.h. The main functions
are:
int lam_debug_open(lam_debug_stream_info_t *lds);
int lam_debug_switch(int lam_debug_id, int fl_enable);
void lam_debug(int lam_debug_id, char *format, ...);
void lam_debug_close(int lam_debug_id);
You open a debug stream with lam_debug_open(). The parameter specifies
where you want the output of that stream to go -- you can multiplex to
multiple locations if you want (a file, stdout, stderr, syslog, etc.).
Then you lam_debug() to send output to that stream. printf-style
substitution is supported (%d, %s, etc.). Later, you close the stream
with lam_debug_close().
You can temporarily enable/disable open streams with lam_debug_switch()
-- i.e., if you disable a stream, any calls to lam_debug() to that
stream will be sent to the bit bucket.
So this is neither elegant nor portable, but it's an option (you'll
probably need to manually copy lamdebug.h to $includedir, or use
--with-trillium when you configure LAM, and lamdebug.h will be
installed for you). :-)
On Oct 21, 2004, at 11:51 AM, Josh Hursey wrote:
>
> On Oct 21, 2004, at 10:20 AM, Bogdan Costescu wrote:
>
>> On Thu, 21 Oct 2004, Josh Hursey wrote:
>>
>>> LAM/MPI redirects stderr and stdout from all 'children' to 'parent'
>>> node, so when a child prints a message to stdout it is actually
>>> printed
>>> on the parents terminal.
>>
>> Hmm, let's be more precise: the stdout/stderr of _mpirun_ is connected
>> to the terminal.
>
> Yes that's what I meant, thanks.
>
>>
>>> What I would like to do is, in software, take this stream and put it
>>> into a file. You can do this in *nix via command line redirection,
>>> but
>>> I need to do it in C.
>>
>> This is the part that is not very clear. Where do you want this C
>> program to run with respect to mpirun and the MPI application ?
>
> This MPI program will run on rank 0 with mpirun. So just after
> MPI_Init I call
> freopen() to route all stdio to a file. I am able to access the stderr
> and stdout
> from the current process, but I need to access the incomming streams
> from other ranks
> so I can route them to the same file [or if necessary another file] on
> the rank 0 node.
>
>> Do you want to do this in the MPI application itself ? I don't think
>> that this is possible; the most reliable way would be to send through
>> MPI the strings from n1-nX nodes to n0 and make only n0 write into a
>> file - then you are already aware of the ordering problem :-)
>
> freopen() was the first solution that occurred to be for this problem
> since it is
> least friction, and reduces the amount of code that has to be
> changed/added to the existing
> structure.
>
> Sending the strings over MPI calls was my second option, but I wanted
> to make sure that
> the first option was invalid before writing a wrapper for
> printf/fprintf.
>
> The ordering problem is a bit of an issue, but we just need a simple
> central 'log' of what
> happens on each node [mostly for debugging]. In general messages to
> stdout are fairly infrequent,
> so we decided to live with disordering of messages for this central
> log since each message has a
> node rank and time stamp associated with it.
>
> Thanks for your help,
> Josh
>
>>
>> --
>> Bogdan Costescu
>>
>> IWR - Interdisziplinaeres Zentrum fuer Wissenschaftliches Rechnen
>> Universitaet Heidelberg, INF 368, D-69120 Heidelberg, GERMANY
>> Telephone: +49 6221 54 8869, Telefax: +49 6221 54 8868
>> E-mail: Bogdan.Costescu_at_[hidden]
>>
>>
>> _______________________________________________
>> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
>
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
>
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|