将输入文件中的字符串参数和命令字符串与GNU并行组合



我试图将命令字符串和单独的参数从输入文件传递到GNU并行。我的脚本看起来像这样:

parallel="parallel --delay 0.2 -j 100 --joblog remaining_runs_$1.log --resume "
$srun $parallel {python3 scaling.py {1} {2} {3}} <  missing_runs_$1.txt

python脚本接受3个单独的整数作为参数,每个整数在missing_runs_$1.txt中列出,如下所示:

1 1 153
1 1 154
1 1 155
1 1 156
1 1 157
1 1 158
...

我尝试过使用--colsep,但它导致只有文件参数被传递到并行缺少python3 scaling.py部分。没有--colsep,每个文件行被解释为一个字符串,这不是我想要的(例如,python3 scaling.py '1 1 153')。什么好主意吗?

在您的输入示例中,我创建了一个可重复的示例来测试此问题:

一个简单的python脚本:
#!/usr/bin/python
import sys
for i in range(1, len(sys.argv)):
print(f'The argument number {i} is {sys.argv[i]}.')

和一个简化的命令行:

parallel --dry-run -j 100 --colsep ' ' ./python.py {1} {2} {3} :::: < missing_runs_1.txt
./python.py 1 1 153
./python.py 1 1 154
./python.py 1 1 155
./python.py 1 1 156
./python.py 1 1 157
./python.py 1 1 158

without--dry-run:

The argument number 1 is 1.
The argument number 2 is 1.
The argument number 3 is 153.
The argument number 1 is 1.
The argument number 2 is 1.
The argument number 3 is 154.
The argument number 1 is 1.
The argument number 2 is 1.
The argument number 3 is 155.
The argument number 1 is 1.
The argument number 2 is 1.
The argument number 3 is 156.
The argument number 1 is 1.
The argument number 2 is 1.
The argument number 3 is 157.
The argument number 1 is 1.
The argument number 2 is 1.
The argument number 3 is 158.
使用并行命令中的所有参数,在文件remaining_runs_1.log中,我得到:
Seq Host    Starttime   JobRuntime  Send    Receive Exitval Signal  Command
1   :   1630591288.009       0.021  0   86  0   0   ./python.py 1 1 153
2   :   1630591288.220       0.040  0   86  0   0   ./python.py 1 1 154
3   :   1630591288.422       0.035  0   86  0   0   ./python.py 1 1 155
4   :   1630591288.649       0.041  0   86  0   0   ./python.py 1 1 156
5   :   1630591288.859       0.042  0   86  0   0   ./python.py 1 1 157
6   :   1630591289.081       0.040  0   86  0   0   ./python.py 1 1 158

我认为这可以解决问题,或者至少为最终解决方案提供新的思路。

If

parallel --delay 0.2 -j 100 --joblog curtailment_scaling_remaining_$1.log --resume python3 scaling.py {1} {2} {3} :::: < missing_runs_$1.txt

给你:

python3 curtailment_scaling.py '1 1 163'

和你想要的

python3 curtailment_scaling.py 1 1 163

你可以执行(version>20190722):

parallel --delay 0.2 -j 100 --joblog curtailment_scaling_remaining_$1.log --resume python3 scaling.py {=uq=} < missing_runs_$1.txt

(uq运行uq();,导致替换字符串不被引用)

或:

parallel --delay 0.2 -j 100 --joblog eval curtailment_scaling_remaining_$1.log --resume python3 scaling.py {} < missing_runs_$1.txt

最新更新