python - 规则定义中“线程”通配符的算术
问题描述
在我的工作流程中,我将两个多线程程序连接在一起。请参阅下面我的 Snakemake 文件中的规则定义。
rule do_the_thing:
input: 'input.dat'
output: 'output.dat'
threads: 16
shell: 'cmd1 --threads {threads} {input} | cmd2 --threads {threads} > {output}'
如所写,该命令将消耗 32 个线程。有没有办法可以对线程变量执行算术运算,以便(例如)每个命令只消耗一半的可用线程?
解决方案
有很多选择:
- 使用cpulimit:
shell:
cpulimit --include-children -l {threads}00 --\
cmd1 --threads {threads} {input} | cmd2 --threads {threads} > {output}
- 计算参数中的线程使用情况:
threads: 16
params: lambda threads: max(1, threads//2)
shell:
cmd1 --threads {params.threads} {input} | cmd2 --threads {params.threads} > {output}
- 利用snakemake管道输出
rule do_the_thing_first:
output: pipe('output.pipe')
threads: 8
shell: 'cmd1 --threads {threads} {input} > {output}'
rule do_the_thing_second:
input: 'output.pipe'
output: 'output.dat'
threads: 8
shell: 'cmd2 --threads {threads} > {output}'
推荐阅读
- mongodb - 有没有办法在 MongoDB Atlas 上测试 M10 Atlas 集群?
- python - 无法导入我自己的文件python,Flask pycharm
- java - 如何在 jframe java swing 中调整 jscrollpane 的大小?
- laravel - 迁移失败,因为路由中间件在测试期间从不存在的表中选择
- javascript - meteorjs 如何将字符串名称作为函数?
- linux - 反应式扩展 .NetCore 在 MainThread 上观察
- java - SQL 查询的准备语句,错误 DB2 SQL 错误:SQLCODE=-206,SQLSTATE=42703
- c# - 组合框,在数据网格视图中,选择不保留 c#
- php - Laravel does not throw 404 when route ends with .php
- tfs - TF2012 终止支持