我正在寻找一种可以从命令行指定的方法:
--jobs
获得,所以在这里一切都很好)。我的规则如下:
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
对象是否具有该资源,但是我什么也没看到)。
谢谢您的帮助!