在多队列模式集群中运行作业 - Amazon ParallelCluster
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

在多队列模式集群中运行作业

本教程介绍如何在多队列模式下运行您的第一Amazon ParallelCluster个Hello World “” 作业。

先决条件

配置集群

首先,通过运行以下命令验证已正确安装。Amazon ParallelCluster

$ pcluster version

有关 pcluster version 的更多信息,请参阅 pcluster version

此命令返回的运行版本Amazon ParallelCluster。

接下来,运行pcluster configure以生成基本配置文件。按照此命令后面的所有提示进行操作。

$ pcluster configure --config multi-queue-mode.yaml

有关 pcluster configure 命令的更多信息,请参阅pcluster configure

完成此步骤后,multi-queue-mode.yaml将出现名为的基本配置文件。此文件包含基本的群集配置。

在下一步中,您将修改新的配置文件并启动包含多个队列的集群。

注意

本教程使用的某些实例不符合免费套餐条件。

在本教程中,修改您的配置文件以匹配以下配置。以红色突出显示的项目代表您的配置文件值。保持自己的价值观。

Region: region-id Image: Os: alinux2 HeadNode: InstanceType: c5.xlarge Networking: SubnetId: subnet-abcdef01234567890 Ssh: KeyName: yourkeypair Scheduling: Scheduler: slurm SlurmQueues: - Name: spot ComputeResources: - Name: c5xlarge InstanceType: c5.xlarge MinCount: 1 MaxCount: 10 - Name: t2micro InstanceType: t2.micro MinCount: 1 MaxCount: 10 Networking: SubnetIds: - subnet-abcdef01234567890 - Name: ondemand ComputeResources: - Name: c52xlarge InstanceType: c5.2xlarge MinCount: 0 MaxCount: 10 Networking: SubnetIds: - subnet-021345abcdef6789

创建 集群

创建一个multi-queue-cluster根据您的配置文件命名的集群。

$ pcluster create-cluster --cluster-name multi-queue-cluster --cluster-configuration multi-queue-mode.yaml { "cluster": { "clusterName": "multi-queue-cluster", "cloudformationStackStatus": "CREATE_IN_PROGRESS", "cloudformationStackArn": "arn:aws:cloudformation:eu-west-1:123456789012:stack/multi-queue-cluster/1234567-abcd-0123-def0-abcdef0123456", "region": "eu-west-1", "version": "3.5.0", "clusterStatus": "CREATE_IN_PROGRESS" } }

有关 pcluster create-cluster 命令的更多信息,请参阅pcluster create-cluster

要查看集群的状态,请运行以下命令。

$ pcluster list-clusters { "cluster": { "clusterName": "multi-queue-cluster", "cloudformationStackStatus": "CREATE_IN_PROGRESS", "cloudformationStackArn": "arn:aws:cloudformation:eu-west-1:123456789012:stack/multi-queue-cluster/1234567-abcd-0123-def0-abcdef0123456", "region": "eu-west-1", "version": "3.5.0", "clusterStatus": "CREATE_IN_PROGRESS" } }

创建集群后,将显示该clusterStatus字段CREATE_COMPLETE

登录头节点

使用您的 SSH 私钥文件登录到头节点。

$ pcluster ssh --cluster-name multi-queue-cluster -i ~/path/to/yourkeyfile.pem

有关 pcluster ssh 的更多信息,请参阅 pcluster ssh

登录后,运行sinfo命令以验证您的调度程序队列是否已设置和配置。

有关的更多信息sinfo,请参阅Slurm文档中的 sinfo

$ sinfo PARTITION AVAIL TIMELIMIT NODES STATE NODELIST spot* up infinite 18 idle~ spot-dy-c5xlarge-[1-9],spot-dy-t2micro-[1-9] spot* up infinite 2 idle spot-st-c5xlarge-1,spot-st-t2micro-1 ondemand up infinite 10 idle~ ondemand-dy-c52xlarge-[1-10]

输出显示您的集群中有一个t2.micro和一个处于该idle状态的c5.xlarge计算节点可用。

其他节点都处于省电状态,由节点状态中的~后缀表示,没有 EC2 实例支持它们。默认队列由其队列名称后的后*缀指示。 spot是您的默认任务队列。

在多队列模式下运行作业

接下来,尝试运行一项工作以使其进入睡眠状态。该作业稍后输出自己的主机名。确保此脚本可以由当前用户运行。

$ tee <<EOF hellojob.sh #!/bin/bash sleep 30 echo "Hello World from \$(hostname)" EOF $ chmod +x hellojob.sh $ ls -l hellojob.sh -rwxrwxr-x 1 ec2-user ec2-user 57 Sep 23 21:57 hellojob.sh

使用sbatch命令提交作业。使用-N 2选项为该任务请求两个节点,并验证任务是否成功提交。有关的更多信息sbatch,请参见 sbatchSlurm 文档中的

$ sbatch -N 2 --wrap "srun hellojob.sh" Submitted batch job 1

您可以使用squeue命令查看队列并查看任务的状态。因为你没有指定特定的队列,所以使用默认队列 (spot)。有关的更多信息squeue,请参阅Slurm文档squeue中的。

$ squeue JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) 1 spot wrap ec2-user R 0:10 2 spot-st-c5xlarge-1,spot-st-t2micro-1

输出显示此作业目前处于运行状态。请等待任务完成。这大约需要 30 秒。然后,squeue再次运行。

$ squeue JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)

现在队列中的任务已全部完成,请查找当前目录slurm-1.out中命名的输出文件。

$ cat slurm-1.out Hello World from spot-st-t2micro-1 Hello World from spot-st-c5xlarge-1

输出显示作业在spot-st-t2micro-1spot-st-c5xlarge-1节点上成功运行。

现在,使用以下命令为特定实例指定约束条件,提交相同的作业。

$ sbatch -N 3 -p spot -C "[c5.xlarge*1&t2.micro*2]" --wrap "srun hellojob.sh" Submitted batch job 2

您将这些参数用于sbatch

  • -N 3— 请求三个节点。

  • -p spot— 将作业提交到队spot列。您也可以通过指定向ondemand队列提交任务-p ondemand

  • -C "[c5.xlarge*1&t2.micro*2]"— 指定此作业的特定节点限制。这要求将一个c5.xlarge节点和两个t2.micro节点用于此作业。

运行sinfo命令查看节点和队列。中的队Amazon ParallelCluster列称为中的分区Slurm。

$ sinfo PARTITION AVAIL TIMELIMIT NODES STATE NODELIST spot* up infinite 1 alloc# spot-dy-t2micro-1 spot* up infinite 17 idle~ spot-dy-c5xlarge-[2-10],spot-dy-t2micro-[2-9] spot* up infinite 1 mix spot-st-c5xlarge-1 spot* up infinite 1 alloc spot-st-t2micro-1 ondemand up infinite 10 idle~ ondemand-dy-c52xlarge-[1-10]

节点正在启动。这由节点状态上的#后缀表示。运行squeue命令可查看集群中任务的相关信息。

$ squeue JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) 2 spot wrap ec2-user CF 0:04 3 spot-dy-c5xlarge-1,spot-dy-t2micro-1,spot-st-t2micro-1

您的任务处于CF (CONFIGURING) 状态,正在等待实例扩展并加入集群。

大约三分钟后,节点可用,任务进入R (RUNNING) 状态。

$ squeue JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) 2 spot wrap ec2-user R 0:07 3 spot-dy-t2micro-1,spot-st-c5xlarge-1,spot-st-t2micro-1

作业完成,所有三个节点都处于idle状态。

$ squeue JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) $ sinfo PARTITION AVAIL TIMELIMIT NODES STATE NODELIST spot* up infinite 17 idle~ spot-dy-c5xlarge-[1-9],spot-dy-t2micro-[2-9] spot* up infinite 3 idle spot-dy-t2micro-1,spot-st-c5xlarge-1,spot-st-t2micro-1 ondemand up infinite 10 idle~ ondemand-dy-c52xlarge-[1-10]

然后,在队列中没有剩余任务后,在本地目录slurm-2.out中进行检查。

$ cat slurm-2.out Hello World from spot-st-t2micro-1 Hello World from spot-dy-t2micro-1 Hello World from spot-st-c5xlarge-1

这是集群的最终状态。

$ sinfo PARTITION AVAIL TIMELIMIT NODES STATE NODELIST spot* up infinite 17 idle~ spot-dy-c5xlarge-[1-9],spot-dy-t2micro-[2-9] spot* up infinite 3 idle spot-dy-t2micro-1,spot-st-c5xlarge-1,spot-st-t2micro-1 ondemand up infinite 10 idle~ ondemand-dy-c52xlarge-[1-10]

注销集群后,您可以运行清理pcluster delete-cluster。有关更多信息,请参阅 pcluster list-clusterspcluster delete-cluster

$ pcluster list-clusters { "clusters": [ { "clusterName": "multi-queue-cluster", "cloudformationStackStatus": "CREATE_COMPLETE", "cloudformationStackArn": "arn:aws:cloudformation:eu-west-1:123456789012:stack/multi-queue-cluster/1234567-abcd-0123-def0-abcdef0123456", "region": "eu-west-1", "version": "3.1.4", "clusterStatus": "CREATE_COMPLETE" } ] } $ pcluster delete-cluster -n multi-queue-cluster { "cluster": { "clusterName": "multi-queue-cluster", "cloudformationStackStatus": "DELETE_IN_PROGRESS", "cloudformationStackArn": "arn:aws:cloudformation:eu-west-1:123456789012:stack/multi-queue-cluster/1234567-abcd-0123-def0-abcdef0123456", "region": "eu-west-1", "version": "3.1.4", "clusterStatus": "DELETE_IN_PROGRESS" } }