我使用SLURM资源管理软件在群集上使用OpenMPI运行我的可执行文件。我想找到一种方法来指定应该为每个节点分配多少和哪些进程,其中每个节点的进程数可能不同。
澄清我要找的内容的一个例子:假设我想在3个节点上运行7个进程。然后我希望能够说出类似的话: 节点1应该运行具有秩n的进程,节点2和3应该运行其余3个进程。
我不关心哪个物理节点是节点1,因为我正在使用的集群上的所有节点都相同。此外,我不知道先前我将由SLURM分配哪些节点,因此我无法在主机文件中对节点的名称进行硬编码。我找到的OpenMPI文档中的一个示例将为我的示例定义这样的主机文件:
aa slots=1
bb slots=3
cc slots=3
但这种方法存在两个问题:
答案 0 :(得分:2)
感谢Hristo Iliev的评论,我找到了问题中所述示例的解决方案:
#!/bin/bash
HOSTFILE=./myHostfile
RANKFILE=./myRankfile
# Write the names of the nodes allocated by SLURM to a file
scontrol show hostname ${SLURM_NODELIST} > $HOSTFILE
# Number of processes
numProcs=7
# Number of nodes
numNodes=${SLURM_JOB_NUM_NODES}
# Counts the number of processes already assigned
count=0
while read p; do
# Write the node names to a rank file
if [ $count == 0 ]
then
echo "rank $count=$p slot=0-7" > $RANKFILE
let count=$count+1
let numNodes=$numNodes-1 # Number of nodes that are still available
else
# Compute the number of processes that should be assigned to this node
# by dividing the number of processes that still need to be assigned by
# the number of nodes that are still available. (This automatically "floor"s the result.)
let numProcsNode=($numProcs-$count)/$numNodes
for i in `seq 1 $numProcsNode`
do
echo "rank $count=$p slot=0-7" >> $RANKFILE
let count=$count+1
done
let numNodes=$numNodes-1 # Number of nodes that are still available
fi
done < $HOSTFILE
mpirun --display-map -np $numProcs -rf $RANKFILE hostname
虽然有点难看。并且“slot = 0-7”可能不应该使用“7”硬编码。