parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash arrays in parallel


From: gsermaid
Subject: Re: bash arrays in parallel
Date: Thu, 12 Jan 2012 15:41:15 +0000 (GMT)

Ok, now suppose that my_program takes two arguments and I want to use parallel to run the program in pairs. For example, if

x=(0.1 0.2 0.3)
y=(0.4 0.5 0.6)

then I want to get:

my_program ${x[0]} ${y[0]}
my_program ${x[1]} ${y[1]}
my_program ${x[2]} ${y[2]}

Now if I use  "parallel my_program ::: ${x[@]} ::: ${y[@]}"
it will run a nested loop, ie arguments will be (0.1, 0.4), (0.1, 0.5), (0.1, 0.6) etc, which is not what I want.

I know I can achieve running in pairs by using a table and --colsep but I was wondering whether I could avoid the use of tables. 
I also know that I could use something like

z=(0.1 0.4 0.2 0.5 0.3 0.6)

and run "parallel -N2 my_program {1} {2} :::: ${z[@]}",

but this is not ideal since I need to create everytime the additional vector z (unless I am unaware of a bash function that combines vectors in that way.)

Ideally, I would like to use something like in my original post

parallel my_program ${x[{1}]} ${y[{1}]} :::: <(seq 0 2)

which of course does not work.

Thanks for any suggestions!



From: giorgos sermaidis <linuxfever@yahoo.gr>
To: Ole Tange <tange@gnu.org>
Cc: "parallel@gnu.org" <parallel@gnu.org>
Sent: Tuesday, 10 January 2012, 16:17
Subject: Re: bash arrays in parallel

Thanks to everyone. All your suggestions work perfectly!


From: Ole Tange <tange@gnu.org>
To:
Cc: "parallel@gnu.org" <parallel@gnu.org>
Sent: Tuesday, 10 January 2012, 15:06
Subject: Re: bash arrays in parallel

On Mon, Jan 9, 2012 at 4:11 PM, Cook, Malcolm <MEC@stowers.org> wrote:

> parallel my_program ::: ${x[@]}

That works if x does not contain spaces. If you have special chars in
the variable and you want each element to be interpreted separately
(i.e. do not split on space) try:

  x=("My brother's 12\" records are worth <\$\$\$>"'!' 0.2 0.3)
  parallel echo ::: "${x[@]}"

/Ole






reply via email to

[Prev in Thread] Current Thread [Next in Thread]