我正在尝试使用 aprun 运行多节点作业。但是,我无法弄清楚如何在 bash 环境中获得排名(或作为每个工作 ID 的任何内容)。就像这个简单的工作:

aprun -n 8 -N 2 ./examplebashscript.sh

我怎样才能在每个产生的工作中获得排名?
如果没有排名或任何唯一作业 ID 之类的东西,这条 aprun 行只会运行完全相同的程序 16 次,这是不可取的。

我一直在阅读文档,令人惊讶的是我找不到任何解释 aprun 提供的默认变量的内容。

我之前使用过 mpirun,我知道如何使用 C 和 Python 程序获取每个作业的排名值,但在 Bash 中不知道。 aprun 的记录更少。

最佳答案

一种可行的方法是编写一个包装脚本,该脚本可以运行一系列任务,然后将每个任务生成到一个单独的脚本中。

在您的片段中,您似乎想为每个计算节点运行 2 个脚本实例以总共获得 8 个,因此,在您的作业脚本中,您可以执行以下操作:

for (( i=0; i<8; i+=2 )); do
   aprun -n 1 ./wrapper.sh $i 2 &
done
wait

然后在包装器中,您可以执行以下操作(其中 $j 为您提供唯一索引):
end=$(( $1 + $2 ))
for (( j=$1; j<$end; j+=1 )); do
   ./examplebashscript.sh $j &
done
wait

您还可以设置以下环境变量来获取各种进程和线程的位置。在运行“aprun”之前,您需要在 shell(或作业脚本)中设置这些:
export MPICH_CPUMASK_DISPLAY=1
export MPICH_RANK_REORDER_DISPLAY=1

例如,运行:
aprun -n 24 ./examplebashscript.sh

(相当于的简写):
aprun -n 24 -N 24 -S 12 -d 1 ./examplebashscript.sh

将在 STDERR 上为您提供以下类型的输出(请注意,这是在每个计算节点具有两个 Intel Ivy Bridge 12 核处理器的 XC30 上,因此由于超线程的存在,掩码显示每个节点上的 48 核位置):
[PE_0]: MPI rank order: Using default aprun rank ordering.
[PE_0]: rank 0 is on nid02749
[PE_0]: rank 1 is on nid02749
[PE_0]: rank 2 is on nid02749
[PE_0]: rank 3 is on nid02749
[PE_0]: rank 4 is on nid02749
[PE_0]: rank 5 is on nid02749
[PE_0]: rank 6 is on nid02749
[PE_0]: rank 7 is on nid02749
[PE_0]: rank 8 is on nid02749
[PE_0]: rank 9 is on nid02749
[PE_0]: rank 10 is on nid02749
[PE_0]: rank 11 is on nid02749
[PE_0]: rank 12 is on nid02749
[PE_0]: rank 13 is on nid02749
[PE_0]: rank 14 is on nid02749
[PE_0]: rank 15 is on nid02749
[PE_0]: rank 16 is on nid02749
[PE_0]: rank 17 is on nid02749
[PE_0]: rank 18 is on nid02749
[PE_0]: rank 19 is on nid02749
[PE_0]: rank 20 is on nid02749
[PE_0]: rank 21 is on nid02749
[PE_0]: rank 22 is on nid02749
[PE_0]: rank 23 is on nid02749
[PE_23]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000100000000000000000000000
[PE_22]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000010000000000000000000000
[PE_21]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000001000000000000000000000
[PE_0]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000000000001
[PE_20]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000100000000000000000000
[PE_9]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000001000000000
[PE_11]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000100000000000
[PE_10]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000010000000000
[PE_8]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000100000000
[PE_1]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000000000010
[PE_2]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000000000100
[PE_18]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000001000000000000000000
[PE_7]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000010000000
[PE_15]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000001000000000000000
[PE_3]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000000001000
[PE_6]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000001000000
[PE_16]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000010000000000000000
[PE_14]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000100000000000000
[PE_13]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000010000000000000
[PE_12]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000001000000000000
[PE_4]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000000010000
[PE_5]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000000000000000100000
[PE_17]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000000100000000000000000
[PE_19]: cpumask set to 1 cpu on nid02749, cpumask = 000000000000000000000000000010000000000000000000

您也许能够以某种方式捕获它以供使用。

关于bash - 如何在aprun中获得排名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29039056/

10-12 20:27