When mpiexec
starts MPI processes, only one of them receives stdin
. The rest will not have that descriptor open, so reading from it will just return an error. If you check the return value from scanf
it will probably be EOF
. Technically there could be an implementation that would copy the contents of stdin
and forward to all processes, but I don't think any MPI does this.
stdout
on the other hand is usually collected from all processes by the launcher, and printed on the terminal, but the order in which things get printed is next to impossible to control. The common solution is to collect the data at one rank manually and have it print everything, as pyCthon suggested.
Finally, OpenMPI's mpiexec
can do the things you asked for: specify which rank will get stdin
, and even launch certain ranks in a separate xterm
. This might be useful for debugging, but I wouldn't rely on these features for core functionality: you might want to use your code with a different MPI implementation some day. Besides, say you are running on a large cluster - do you really want a thousand terminals open? :)