Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9541
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Incorrect parallel computation |
| Date | 2012-04-10 06:31 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jm0k4t$agm$1@smc.vnet.net> (permalink) |
| References | <jlrhi8$eoe$1@smc.vnet.net> |
On 08/04/2012 09:17, Yasha Gindikin wrote:
> Dear colleagues,
>
> would you please advise me on why the following simple code executes incorrectly when parallelized?
>
> a = Subsets[Range[1, 5], {3}];
> L = Length@a;
> b = Table[0, {5}];
> c = Table[0, {5}];
> SetSharedVariable[c];
> Do[b[[a[[l, k]]]] += 1, {l, L}, {k, 3}];
> ParallelDo[c[[a[[l, k]]]] += 1, {l, L}, {k, 3}];
> b===c
>
> False
>
> Thank you!
> Best regards,
> Yasha Gindikin.
>
I think this illustrates the pitfalls of parallel computing - which is
why I have never used this feature for serous code!
Notice the "Possible issues" section of the help for SetSharedVariable.
You probably thought your update was atomic, but I doubt if
c[[a[[l, k]]]] += 1
qualifies as an atomic update!
Every now and again I toy with the idea of using parallel constructs -
so thanks for reminding me of why it is not a good idea, and saving me
much heartache!
David Bailey
http://www.dbaileyconsultancy.co.uk
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Incorrect parallel computation Yasha Gindikin <gindikin@gmail.com> - 2012-04-08 08:17 +0000
Re: Incorrect parallel computation David Bailey <dave@removedbailey.co.uk> - 2012-04-10 06:31 +0000
Re: Incorrect parallel computation Yasha Gindikin <gindikin@gmail.com> - 2012-04-11 22:20 +0000
Re: Incorrect parallel computation Zach Bjornson <bjornson@stanford.edu> - 2012-04-11 22:22 +0000
csiph-web