4

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

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

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

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

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

4

3 回答 3

1

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

在您的片段中,您似乎想为每个计算节点运行 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 上为您提供以下类型的输出(请注意,这是在 XC30 上,每个计算节点有两个 Intel Ivy Bridge 12 核处理器,因此由于超线程的存在,掩码显示每个节点有 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

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

于 2015-06-15T18:37:52.473 回答
1

尝试在您已 aprun-ed 的 bash 脚本中查找环境变量ALPS_APP_PE

脚本的每个实例都会有所不同(创建的实例数由 aprun 命令中的 -n 选项给出)。

如果脚本随后执行 MPI 程序的实例,则该实例将具有由 ALPS_APP_PE 给出的 MPI 等级值。

需要注意的是,某些 Cray 站点可能决定不公开此变量,或使用不同的名称。非常旧的 ALPS 版本也不支持它,但这些很少见。

有关示例,请参阅此 CUG 2014 论文:

https://cug.org/proceedings/cug2014_proceedings/includes/files/pap136.pdf

于 2015-06-16T10:51:32.953 回答
0

假设您在最近的 Cray 上运行,则不能。您的脚本在登录节点上执行,aprun命令在计算节点上启动应用程序。

您启动的应用程序可以通过初始化 MPI 然后调用MPI_Rank.

于 2015-06-09T09:26:21.583 回答