如何判断哪个节点正在执行 Slurm 中的代码?

How to tell which node is executing code as it executes in Slurm?

我对 Slurm 和 distributed/parallel 计算还很陌生,所以希望有人能阐明我的问题,但请记住,这可能是一个需要解决的简单问题。

我已经使用 6 个从属 Pi3(和 1 个主控)设置了一个集群,并安装了 Slurm 工作负载管理器来帮助分配资源等。

在进入更复杂的代码之前,我正在尝试测试一些超级简单的东西。我正在向所有节点发送相同的命令,并打印节点的主机名。

我当前的代码(有效)是:

srun --nodes=6 hostname

和returns:

node01
node05
node04
node02
node06
node03

现在我尝试 运行 使用带有以下脚本的 sbatch 的相同类型的命令:

 #!/bin/bash
 #SBATCH --nodes=6
 #SBATCH --partition=partition
 #SBATCH --ntasks-per-node=1

 cd $SLURM_SUBMIT_DIR
 srun printf ‘Hello from: %s\n’ $(hostname) >> out.txt

期待与上面类似的结果,但我得到的是:

Hello from: node01
Hello from: node01
Hello from: node01
Hello from: node01
Hello from: node01
Hello from: node01

我尝试使用 SLURM_NODEID 和 SLURMD_NODENAME 环境变量,但仍然无法按照我的意愿进行操作。

我只想知道哪个节点正在 运行ning 代码。目的是为了让我能够更深入地跟踪哪些操作是由哪些节点完成的,以获得更复杂的脚本。也许比较预期 "identical" 的节点之间的性能。甚至可以跟踪哪些节点正在执行并行化案例的哪一部分?

非常感谢!!!!

printf ‘Hello from: %s\n’ $(hostname) >> out.txt 部分在提供给 srun 之前由 Bash 评估。所以基本上你的脚本相当于

HOST=$(hostname)
srun printf ‘Hello from: %s\n’ $HOST >> out.txt

此 运行 是相同的 printf 命令,但扩展了相同的变量。如果你只是 运行

srun hostname

在您的提交脚本中,您将看到与直接 运行ning srun(在提交脚本之外)获得的结果相同的结果

如果你想 运行 printf 你应该这样做:

srun bash -c "printf 'Hello from: %s\n' $(hostname)" >> out.txt