To sample an MPI application you need to create a small wrapper script around your application. For example, if you are using Open MPI and want to run the MPI application mpi-test, your script could look like the following example:
#!/bin/sh sample -o rank$OMPI_MCA_ns_nds_vpid.smp -r mpi-test "$@"
The environment variable OMPI_MCA_ns_nds_vpid
is
specific to Open MPI and contains the rank number that will be
started by the script. If you are using another MPI
implementation it may provide a similar environment variable.
Consult your MPI implementation's documentation for details. For
instance, HP MPI stores the rank id in an environment variable
is called MPI_RANKID
, this means that the same
script for HP MPI would look like this:
#!/bin/sh sample -o rank$MPI_RANKID.smp -r mpi-test "$@"
If your MPI implementation does not provide such a variable you can replace the rank in the file name with another unique identifier of the rank. For example, the host name and the PID of the script. The following script is an example of this:
#!/bin/sh sample -o rank-$HOSTNAME-$$.smp -r mpi-test "$@"
You then start the script through mpirun, and
the script will start and sample each rank. For example, if you
have named the script sample.sh
you could
execute mpirun -np 2 sample.sh for a
2-process run.
The script samples each rank of the MPI application mpi-test and
creates a sample file named rank0.smp
for
rank 0, rank1.smp
for rank 1, and so on
…
The scripts above assumes that the sample command is available
in the PATH
everywhere mpirun
starts the script, and the sample file will be created in the
working directory where mpirun starts the
script.
If the rank is available through an environment variable, you can also selectively sample ranks. For example, the following script would sample rank 0 and run the other ranks unsampled with Open MPI:
#!/bin/sh if [ $OMPI_MCA_ns_nds_vpid == 0 ]; then sample -o rank$OMPI_MCA_ns_nds_vpid.smp -r mpi-test "$@" else mpi-test "$@" fi