antong antong - 1 year ago 124
Perl Question

Math in GNU Parallel

The one thing I'm trying to do, is have a little bit of math done with the {%} option in GNU Parallel

cat short | parallel -j 2 echo my_prog ----in {} ----out {/.}.extension ----gpu {= {%}+1 =} {= {%}-1 =}

(I have extra dashes in front of
just in case.)

The math shown within
{= =}
is all I need to do, and I'm just not sure I understand how to write it with

{= =}
is the space where one can write a Perl expression in GNU parallel.

Also my program isn't running here, I'm just echoing the output to see if everything will be correct.

Could someone please explain how to do this simple math within the command?

My error is this:

parallel: Error: Cannot use {%}+1 : Missing right curly or square bracket at (eval 13) line 2, at end of line
syntax error at (eval 13) line 2, at EOF

Answer Source

Problem #1

You need to escape the Perl program so it doesn't get processed by the shell. Using single quotes around the program is the usual method used.

Problem #2

Looks like {%} is not replaced within {= =}, which makes sense. {= =} says "you have full access to all of GNU parallel's internal functions and data structures", so it becomes a question of finding the var/fun that provides the slot number.

Problem #3

It's the value of $_ that's inserted into the command, so you need to assign the sum to $_.


{= '$_ = $job->slot() + 1' =}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download