bug-parallel
[Top][All Lists]
Advanced

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

Re: GNU Parallel Bug Reports parallel can't ressigned variablen in the s


From: Andreas Bernauer
Subject: Re: GNU Parallel Bug Reports parallel can't ressigned variablen in the same context in same file
Date: Thu, 31 May 2012 13:46:47 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

On 5/31/12 12:02, gmail wrote:
> My aim is that shell variable which in parallel  can modify in the whole
> shell script context ,
> 
> the sample code below like that:
> enviroment : centos  5.5 x64 (bash 3.2.25)
> ##############
> #!/bin/bash
> domains=('www1'  'www2')
> counter=0
> parallel -j 2 "if [ -z $counter ];then echo 'var no set
> ';fi;counter=$((counter + 1));echo $counter {1} " ::: address@hidden
> 
> ##############
> the variable  counter no  to be increased when looping the array domains
> ,  counter should be 2,but in parallel it print zero ( no changed)
> 
>  i hope i can describe my quesion  for help above  like that.

You cannot do that with parallel.

You must understand that parallel starts different processes for each
input (here: 'www1', 'www2'); these processes (usually) do not share
memory, so they cannot arbitrarily mutate a common variable (here:
$counter).

However, for your 'counter' example, there is $PARALLEL_SEQ (or '{#}'
for short) which contains the current job number:

########
$ cat /tmp/par
#!/bin/bash
domains=('www1'  'www2')
counter=0
parallel -j 2 "echo \$PARALLEL_SEQ {1} " ::: address@hidden

$ bash /tmp/par
1 www1
2 www2
########

If that doesn't do what you try to achieve, you need some form of
inter-process communication (e.g., via file system, signalling, sockets,
shared memory, etc.), which is beyond what parallel does for you.



reply via email to

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