|
From: | Nagesh Adluru |
Subject: | Re: Positional arguments in nested parallel |
Date: | Sun, 25 Dec 2022 23:19:12 +0000 |
Thank you so much for the detailed reply, Ole! Very helpful!
Sincerely,
Nagesh
From: Ole Tange <ole@tange.dk>
Sent: Sunday, December 25, 2022 5:15 PM To: Nagesh Adluru <adluru@wisc.edu> Cc: parallel@gnu.org <parallel@gnu.org> Subject: Re: Positional arguments in nested parallel On Thu, Dec 22, 2022 at 9:52 PM Nagesh Adluru <adluru@wisc.edu> wrote:
> > Firstly, I would like to sincerely thank you for building and supporting such a wonderful program. I really love using it. This is my first time asking a question on the forum but I have been using the parallel for years now. Great to hear. > I was wondering how to access positional arguments within the nested parallel. You cannot. But an easy workaround is to define a function and call that. It will also avoid quoting and make your code more readable. See below. > I was trying to use a --rpl within the nested parallel to separate the arguments but the sed logic doesn't seem to be working as expected within that. > > parallel -k 'parallel -I // --rpl '\''{i} s:\s.*$::'\'' --rpl '\''{ii} s:[^ ]* ::;s:\s.*::'\'' --rpl '\''{iii} s:.*\s::'\'' echo {1} {i},{ii},{iii} ::: 1 2 :::+ 3 4 :::+ 5 6' ::: A B C D :::+ a b c d It is not clear what you wanted this to generate. Maybe this: doit() { parallel echo $1 $2 '{=1 s:\s.*$:: =},{=2 s:[^ ]* ::;s:\s.*:: =},{=3 s:.*\s::=}' ::: 1 2 :::+ 3 4 :::+ 5 6 # or maybe simply this: parallel echo $1 $2 {1},{2},{3} ::: 1 2 :::+ 3 4 :::+ 5 6 } export -f doit parallel -k doit ::: A B C D :::+ a b c d A a 1,3,5 A a 2,4,6 A a 1,3,5 A a 2,4,6 B b 1,3,5 B b 2,4,6 B b 1,3,5 B b 2,4,6 C c 1,3,5 C c 2,4,6 C c 1,3,5 C c 2,4,6 D d 1,3,5 D d 2,4,6 D d 1,3,5 D d 2,4,6 > For example, if we use sed we can extract Be aware that {= =} uses perl expressions. A lot of sed expressions will work with no change but that is simply because they are also valid perl expressions. > # a using > echo a b c | sed 's:\s.*$::' echo a b c | parallel echo {=1 's:\s.*$::' =} > # b using > echo a b c | sed 's:[^ ]* ::;s:\s.*::' echo a b c | parallel echo {=1 's:[^ ]* ::;s:\s.*::' =} > # c using > echo a b c | sed 's:.*\s::' echo a b c | parallel echo {=1 's:.*\s::' =} > I do realize there are ways to avoid this situation but I really wanted to try and get positional arguments in the nested parallel approach just for pure curiosity reasons. I understand that. The technical reason is that you cannot rename {1} {2} {3}. These are hardcoded. So the outer parallel will always replace these in the command meant for the inner parallel. You can avoid that by making a bash function. The performance penalty is tiny. > Also, heartiest happy seasons greetings and Happy New Year to everyone! You too. /Ole |
[Prev in Thread] | Current Thread | [Next in Thread] |