将qsub与snakemake一起使用时,限制线程总使用量,作业数以及每个规则的最大线程数

时间:2018-10-18 17:04:33

标签: snakemake

我正在寻找一种可以从命令行指定的方法:

  1. 要同时使用的线程总数(即使有多个作业)
  2. 要并行运行的最大作业数(我目前已成功使用--jobs获得,所以在这里一切都很好)。
  3. 如果要使用的最大线程数大于为特定规则指定的线程数,请为此特定规则使用两者之间的最小值。

我的规则如下:

rule a:
    input: "{sample}.in"
    output: "{sample}.out"
    threads: 10
    shell: "some-program --threads {threads}"

rule b:
    input: expand("{sample}.out", sample=SAMPLES)
    output: touch("done.done")
    threads: 1
    shell: "do something"

当我使用--cluster将作业提交到群集并且使用qsub包装器时,命令行如下所示:

snakemake --cluster "qsub-wrapper --threads {threads}" --jobs N

,因此我指定了每个作业要分配的线程数。然后,将--jobs参数解释为要并行提交给集群的作业数,但不限制将使用的线程总数。

例如,如果我使用--jobs 2,则规则a的2个实例将并行运行,总共占用20个线程。

我发现的解决方案是使用--resources,我在其中添加了每个规则:

resources: nodes=NUMBER_OF_THREADS

NUMBER_OF_THREADS就是我为线程定义的内容,因此上面的示例如下所示:

rule a:
    input: "{sample}.in"
    output: "{sample}.out"
    threads: 10
    resources: nodes=10
    shell: "some-program --threads {threads}"

rule b:
    input: expand("{sample}.out", sample=SAMPLES)
    output: touch("done.done")
    threads: 1
    resources: nodes=1
    shell: "do something"

现在我运行:

snakemake --cluster "qsub-wrapper --threads {threads}" --jobs N --resources nodes=10

现在,即使根据--jobs可以提交2个作业,但由于资源的限制,只能提交一个。

有更好的方法吗?

还有,我是否可以从蛇文件中访问资源变量?我要这样做的原因是,我现在面临一个不同的问题:如果资源低于某个规则的线程,那么该规则就永远不会提交到队列中,因此我想做的是这样的事情:

rule a:
    input: "{sample}.in"
    output: "{sample}.out"
    threads: min(10, command_line_specified_resources.nodes)
    resources: min(10, command_line_specified_resources.nodes)
    shell: "some-program --threads {threads}"

但是我还没有找到一种方法来访问命令行中指定的资源(我尝试查看workflow对象是否具有该资源,但是我什么也没看到)。

谢谢您的帮助!

0 个答案:

没有答案