Gnu-Parallel
使用 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)"
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=}