与 Gnu Parallel 并行运行多个 Gnuplot 命令

与 Gnu Parallel 并行运行多个 Gnuplot 命令

我想并行运行 Gnuplot 命令列表。

我收到“无法识别的选项”错误:

$ ./parallel-plot-sine.sh | parallel -q gnuplot
unrecognized option -e "set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)"

我认为这表明 Gnuplot 对它所输入的命令不满意,但我不明白为什么。

shell 脚本parallel-plot-sine.sh组成了将输入到 Gnu Parallel 中的命令:

#!/bin/bash

# Compose command-lines to run in parallel
command_array=()
for fs in $(seq 100 100 1000); do
    command_array+=("-e \"set terminal pngcairo; set output '${fs}.png'; set title 'Sample rate: $fs'; set key left box; set autoscale; set samples $fs; plot [-30:20] sin(x)\"")
done

# Print command strings to output for gnu parallel
for cmd in "${command_array[@]}"; do
    printf "%s\n" "$cmd"
done

这打印:

$ ./parallel-plot-sine.sh
-e "set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '200.png'; set title 'Sample rate: 200'; set key left box; set autoscale; set samples 200; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '300.png'; set title 'Sample rate: 300'; set key left box; set autoscale; set samples 300; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '400.png'; set title 'Sample rate: 400'; set key left box; set autoscale; set samples 400; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '500.png'; set title 'Sample rate: 500'; set key left box; set autoscale; set samples 500; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '600.png'; set title 'Sample rate: 600'; set key left box; set autoscale; set samples 600; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '700.png'; set title 'Sample rate: 700'; set key left box; set autoscale; set samples 700; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '800.png'; set title 'Sample rate: 800'; set key left box; set autoscale; set samples 800; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '900.png'; set title 'Sample rate: 900'; set key left box; set autoscale; set samples 900; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '1000.png'; set title 'Sample rate: 1000'; set key left box; set autoscale; set samples 1000; plot [-30:20] sin(x)"

这些命令独立工作,如下所示:

gnuplot -e "set terminal pngcairo; set output '1000.png'; set title 'Sample rate: 1000'; set key left box; set autoscale; set samples 1000; plot [-30:20] sin(x)"

答案1

默认情况下,GNU 并行引号输入。您提供的输入已被引用。有几种解决方案。

更改输入:

-e "set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)"

到:

set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)

并运行:

... | parallel gnuplot -e

或者:

... | parallel eval gnuplot

# Requires version >= 20190722
... | parallel gnuplot {=uq=}

相关内容