0

I am trying to run mpirun from the master node. If I do the following:

mpirun -np 2 -hostfile /job/hostfile --map-by node --tag-output -bind-to none hostname

The output looks good, two different hosts:

[1,1]<stdout>:azeuscc9800000I
[1,0]<stdout>:azeuscc9800001H

But when I run:

mpirun -np 2 -hostfile /job/hostfile --map-by node --tag-output -bind-to none echo $HOSTNAME

I get the same host printed twice:

[1,1]<stdout>:azeuscc9800001H
[1,0]<stdout>:azeuscc9800001H

It seems the $HOSTNAME variable (and probably other env variables) gets evaluated before mpirun sends the command to the remote node, which defeats the purpose. I have tried using the '-x' parameter unsuccessfully as well (same output, same master hosts printed):

mpirun -np 2 -hostfile /job/hostfile --map-by node --tag-output -bind-to none -x HOSTNAME=$HOSTNAME echo $HOSTNAME

But from what I understand, this parameter is used to export the master env variable to the other nodes, whereas I want the local env variable assignment on each node to be used in the command for each node.

Does anyone know if I am using the mpirun command incorrectly, or if there is something else that needs to be done to achieve this functionality?

user
  • 30
  • 3
  • 1
    $HOSTNAME is evaluated by the shell in which you run mpirun. So you are really calling mpirun azeuscc9800001H – Gilles Gouaillardet Jul 26 '22 at 22:18
  • I can't tell what you're really trying to do. You could write a shell program that prints the hostname, and run that in parallel with mpirun. You could also try escaping the dollar. – Victor Eijkhout Jul 26 '22 at 22:25
  • 1
    the oneliner here is `mpirun ... bash -c 'echo $HOSTNAME'` (assuming your MPI implementation does not propagate `$HOSTNAME` from the head node). – Gilles Gouaillardet Jul 27 '22 at 01:50
  • @GillesGouaillardet Wow and thanks. I tried earlier except using the same thing (bash -c) with double-quotes and it didn't work. I have little to no experience with bash so hopefully will get better at this over time – user Jul 27 '22 at 02:40
  • 1
    you need to escape `$`, so with double quotes, you would `mpirun ... bash -c "echo \$HOSTNAME"` – Gilles Gouaillardet Jul 27 '22 at 05:44

0 Answers0