1

I would like to run a list of Gnuplot commands in parallel.

I'm getting an "Unrecognized option" error:

$ ./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)"

I think this indicates that Gnuplot isn't happy with the command it's being fed, but I can't figure out why.

The shell script parallel-plot-sine.sh composes the commands that will feed into 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

This prints:

$ ./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)"

These commands work on their own like this:

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)"
2
  • 2
    I think the issue is that the quotes don't do what you think they do - outside of the context of a shell, "set is a literal token. Try having your script output the bare commands set terminal pngcairo; set ... and then run them using parallel -q gnuplot -e Jun 4, 2021 at 19:03
  • Thanks! This solved it. I removed the escaped quotes as well as the -e. And the -q for parallel doesn't seem to make a difference in how it's run. I think because there's nothing to expand in the 2nd expansion. Jun 4, 2021 at 19:46

1 Answer 1

1

GNU Parallel quotes input by default. You give input that is already quoted. There are several solutions.

Change the input from:

-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)"

to:

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)

and run:

... | parallel gnuplot -e

Alternatively:

... | parallel eval gnuplot

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .