MPI - Suppress output from some processors
Asked Answered
S

1

5

Is there a way to make MPI just print the output from one (or a subset) of the processes? I know how to do that on code level, but I am wondering whether there is some way to specify this after the executable has already been compiled. I am thinking of getting the output as in one of the windows in the following command

mpirun -np [#processes]  xterm -e [path to executable]

just without using xterm.

I know that I can tag the output using the -tag-output option and then can filter it by hand, but this is kind of tedious. As MPI knows exactly where the output is coming from, is there no easier way to accomplish this goal?

Suture answered 13/12, 2013 at 10:18 Comment(2)
There is nothing in the MPI standard (any of them) to help you. Your implementation of MPI might provide such a feature though (a) you haven't told us what implementation you are using and (b) I, for one, will be surprised to find that any implementation does have this feature.Beersheba
That's unfortunate - is it such a strange thing to ask for? I am using OpenMPI 1.4.3. Thank you for your comment anyway; at least I know I can most probably stop looking for it.Suture
S
9

You could write a wrapper script. Since Open MPI makes the process rank in MPI_COMM_WORLD available in an environment variable called OMPI_COMM_WORLD_RANK, it is very easy to do something like:

#!/bin/bash

UNMUTE=$1
shift 1

if [ "$OMPI_COMM_WORLD_RANK" == "$UNMUTE" ]; then
  exec $*
else
  exec $* >/dev/null 2>&1
fi

Save this to unmute.sh and execute it like:

$ mpiexec -n #procs unmute.sh #rank executable [params]

The script redirects the standard output and error streams to /dev/null for all ranks except for the one specified. You could make the comparison logic more elaborate, e.g. compare against a range or a list of ranks.

Here is a sample of the above script in action:

$ mpiexec -n 6 printenv | grep COMM_WORLD_RANK
OMPI_COMM_WORLD_RANK=0
OMPI_COMM_WORLD_RANK=1
OMPI_COMM_WORLD_RANK=2
OMPI_COMM_WORLD_RANK=3
OMPI_COMM_WORLD_RANK=4
OMPI_COMM_WORLD_RANK=5
$ mpiexec -n 6 unmute.sh 3 printenv | grep COMM_WORLD_RANK
OMPI_COMM_WORLD_RANK=3
Saltwater answered 13/12, 2013 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.