Bill Allombert on Fri, 17 Jan 2025 22:50:26 +0100


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

Re: shared variables in parfor()


On Fri, Jan 17, 2025 at 03:31:17PM -0500, Max Alekseyev wrote:
> Hello,
> 
> I naively thought that the following code would print a few zeros, which
> would then follow by all ones:
> 
> my(q=0); parfor(i=1,10^6, print(q); 0, R, q=1)
> 
> but it constantly prints zeros. So, the value of q is not shared between
> threads.
> What is the right way to create a shared variable (with pthreads if that
> matters)?

It is not possible. This is by design.

Cheers,
Bill.