What's the "right" way to do openmp-style parallelism?
Russel Winder via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Sep 9 00:46:06 PDT 2015
On Tue, 2015-09-08 at 07:33 +0000, Dominikus Dittes Scherkl via
Digitalmars-d-learn wrote:
> On Tuesday, 8 September 2015 at 05:50:30 UTC, Russel Winder wrote:
> > void main() {
> > immutable imax = 10;
> > immutable jmax = 10;
> > float[imax][jmax] x;
> > foreach(int j; 1..jmax){
> > foreach(int i, ref item; parallel(x[j-1])){
> > x[j][i] = complicatedFunction(i, item);
> > }
> > }
> > }
> >
> > (though sadly, this doesn't compile for a reason I can't fathom
> > instantly)
> Hmm. Shouldn't you instead parallel the outer loop?
Can't do that because it is a pipeline: the current computation is
input to the next one. As far as I can tell there is no way the code as
presented can be parallelized in the general case. If there were some
guarantees on complicatedFunction, then it is a different game.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150909/8977fd2f/attachment.sig>
More information about the Digitalmars-d-learn
mailing list