2

During the execution of a C compiled program in a terminal, isatty(fileno(stderr)) as well as isatty(0) returns 0 in my code when I use the mpirun or mpiexec commands.

Why ? and How do I know if stdout is a terminal or redirected while using MPI ?

I'm actually printing colored stuff, but this makes the output parsing harder.

Thanks in advance.

  • MPI processes are started through an ssh tunnel. So std out goes through the tunnel. I have no idea what `isatty` says about that. – Victor Eijkhout Jul 28 '22 at 17:12
  • @VictorEijkhout Hi, and thanks for your reply. I can't find anything related to MPI processes using ssh tunnels, except when using MPI over multiple computers over ssh. Could you provide more information about what you are talking about ? – infrahinium Jul 28 '22 at 20:48
  • See the accepted answer. That says it all. – Victor Eijkhout Jul 28 '22 at 22:05

1 Answers1

3

mpirun/mpiexec starts all processes with stdout/stderr connected to a pipe or socket that leads back to the mpirun process. The mpirun process collects everything from all of these pipes/sockets and copies it to its stdout.

So only mpirun itself still has stdout/stderr still connected to a terminal. Any other process will see its stdout/stderr connected to a non-terminal.

Your best bet is to use an argument or environment variable to control whether the output is colored or not.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226