如何在 Slurm 脚本中编写主机文件
How to write hostfile in Slurm script
目前我正在关注
#!/bin/bash -l
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=4
scontrol show hostname $SLURM_JOB_NODELIST | perl -ne 'chomb; print "$_" x4' > myhostfile
这会生成以下 myhostfile
compute-0
compute-0
compute-0
compute-0
compute-1
compute-1
compute-1
compute-1
我希望得到以下结果
compute-0
compute-1
compute-0
compute-1
compute-0
compute-1
compute-0
compute-1
以便我们在所有指定节点之间交替
你可以这样做:
$ perl -e 'print +(<>) x 4'
这将从您的代码中删除 -n
循环,而是一次性读取整个 STDIN
。我们需要括号 ()
来让读取运算符进入列表上下文,因此它会一次读取所有行。 +
告诉 perl 解释器括号是一个列表,而不是 print
的一部分(如 print()
)。最后,列表上下文中的重复运算符 x
会重复整个列表。
$ cat foo
0
1
$ cat foo | perl -e 'print +(<>) x 4'
0
1
0
1
0
1
0
1
目前我正在关注
#!/bin/bash -l
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=4
scontrol show hostname $SLURM_JOB_NODELIST | perl -ne 'chomb; print "$_" x4' > myhostfile
这会生成以下 myhostfile
compute-0
compute-0
compute-0
compute-0
compute-1
compute-1
compute-1
compute-1
我希望得到以下结果
compute-0
compute-1
compute-0
compute-1
compute-0
compute-1
compute-0
compute-1
以便我们在所有指定节点之间交替
你可以这样做:
$ perl -e 'print +(<>) x 4'
这将从您的代码中删除 -n
循环,而是一次性读取整个 STDIN
。我们需要括号 ()
来让读取运算符进入列表上下文,因此它会一次读取所有行。 +
告诉 perl 解释器括号是一个列表,而不是 print
的一部分(如 print()
)。最后,列表上下文中的重复运算符 x
会重复整个列表。
$ cat foo
0
1
$ cat foo | perl -e 'print +(<>) x 4'
0
1
0
1
0
1
0
1