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.
CodePudding user response:
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.