Update: you only need the following:
mpirun -N 1 -n 2 bash -c 'echo $(hostname): $(cat /sys/devices/virtual/dmi/id/board_asset_tag | tr -d " ")'
- Create a file
get-instance-id.sh
:
#!/bin/bash
hostname=$(hostname)
token=$(curl -sX PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
instance_id=$(curl -sH "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/meta-data/instance-id)
echo "$hostname -> $instance_id"
- Add the following snippet to your Slurm submit script, the three lines at the top are optional.
#!/bin/bash
#SBATCH -N 2
#SBATCH --exclusive
# get all nodes allocated to the job.
NODES=$( scontrol show hostnames $SLURM_JOB_NODELIST )
for node in $NODES
do
srun -w $node -N 1 bash get-instance-id.sh
done
- Then run and you'll get the following output:
ubuntu@p5-st-p5-1:~$ sbatch hostnames.sh
Submitted Job 20
ubuntu@p5-st-p5-1:~$ cat slurm-20.out
p5-st-p5-1 -> i-0f53b99e0960906ed
p5-st-p5-2 -> i-0221a76c26c555381