SLURM:Shell 命令导致以下 #SBATCH 命令无法解析

SLURM : Shell commands cause following #SBATCH commands to not get parsed

我不熟悉 SLURM 并将其与 OpenMP 结合使用。我创建了一个 C 程序,main.c:

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <time.h>

void wait(int s)
{
    int waittime = time(0) + s;
    while(time(0) < waittime);
}


int main(void)
{
    int id=-1;
    int nthreads = 0;

    #pragma omp parallel \
    private(id)
    {   
        nthreads = omp_get_num_threads();
        id = omp_get_thread_num();
        printf("Hello from thread = %i\n",id);

        if(id == 0)
            printf("nthreads = %i\n", nthreads);

        //Let's wait
        wait(60);
    }   

    return 0;
}

和一个 slurm 批处理脚本,slurm.sh:

#!/bin/bash
#SBATCH --cpus-per-task=10
#SBATCH --job-name=OpenMP
#SBATCH --output output.txt
echo "Hello"

#SBATCH --mem-per-cpu=100  

export OMP_NUM_THREADS=10

./a.out

如果我提交(即 sbatch slurm.sh),这个 SLURM 很乐意为我的工作分配 10 个 cpu。如果我把 echo "Hello" 放在 #SBATCH --cpus-per-task=10 之前,我只会分配到 1 CPU。这里发生了什么?我不明白为什么,我的批处理脚本中 shell 命令的位置会更改分配的 CPU 数量。

::Edit:: 进一步检查后发现 any shell 命令(例如 date , echo, set) 似乎导致 sbatch 忽略所有后续 #SBATCH 命令。例如,在我的批处理脚本中,我可以设置 #SBATCH --mem-per-cpu=1000000,它会在 128GB 的​​机器上愉快地 运行。如果我将 #SBATCH --mem-per-cpu=1000000 移动到 echo 之前的一行,SLURM 会适当地给我一个错误。

您不能在 #SBATCH 指令之间添加任何命令。

来自 sbatch 手册页:

The batch script may contain options preceded with "#SBATCH" before any executable commands in the script.