“工作”、“任务”和“步骤”这些术语之间有何关联?

47

如何理解SLURM文档中的“job”、“task”和“step”这些术语?

据我了解,一个作业可以包含多个任务和步骤,但即使是这样,任务和步骤之间的关系仍不清楚。

通过示例展示作业/任务/步骤的完整复杂性将会很有帮助。

1个回答

61

工作由一个或多个步骤组成,每个步骤都包含一个或多个任务,每个任务使用一个或多个CPU

通常使用sbatch命令创建作业,使用srun命令创建步骤,在作业级别使用--ntasks--ntasks-per-node请求任务,在步骤级别使用--ntasks。使用--cpus-per-task为每个任务请求CPU。请注意,使用sbatch提交的作业有一个隐式步骤;Bash脚本本身。

假设有如下假想作业:

#SBATCH --nodes 8
#SBATCH --tasks-per-node 8
# The job requests 64 CPUs, on 8 nodes.    

# First step, with a sub-allocation of 8 tasks (one per node) to create a tmp dir. 
# No need for more than one task per node, but it has to run on every node
srun --nodes 8 --ntasks 8 mkdir -p /tmp/$USER/$SLURM_JOBID

# Second step with the full allocation (64 tasks) to run an MPI 
# program on some data to produce some output.
srun process.mpi <input.dat >output.txt

# Third step with a sub allocation of 48 tasks (because for instance 
# that program does not scale as well) to post-process the output and 
# extract meaningful information
srun --ntasks 48 --nodes 6 --exclusive postprocess.mpi <output.txt >result.txt &

# Fourth step with a sub-allocation on a single node   
# to compress the raw output. This step runs at the same time as 
# the previous one thanks to the ampersand `&` 
srun --ntasks 12 --nodes 1 --exclusive compress.mpi output.txt &

wait

创建了四个步骤,因此该作业的会计信息将有5行;每个步骤一个加上一个用于Bash脚本本身。


4
还有一个问题:为什么需要在结尾加上 wait 命令?如果接下来没有后续步骤需要等待之前的步骤全部完成才能执行,我可以理解在 wait 命令之后还有其他步骤时需要加上它,但是如果它是脚本中的最后一条命令,我不明白它的目的是什么。换句话说,如果省略掉末尾的 wait 命令会发生什么? - kjo
9
wait 命令用于确保带有 & 符号(步骤 3 和 4)的两个 srun 命令在作业被认为完成并终止之前已经完成。如果没有这个命令,脚本会在步骤未完成时终止;此时 Slurm 将认为作业已完成,并杀死所有仍在运行的步骤。 - damienfrancois
2
所有任务并不一定做完全相同的事情。在MPI程序中,任务根据它们的“rank”执行不同的操作。通常,只有排名为0的任务,“master”,才负责编写最终输出。 - damienfrancois
2
“task”和“process”是相同的吗? - nn0p
3
简短回答是“是”。长回答是,“task”是Slurm分配单元,“process”是Linux正在运行的进程;进程是由提交脚本中的命令创建的,并映射到与作业分配的任务相关联的CPU上。 - damienfrancois
显示剩余9条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接