Multithreading in D

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 2 04:40:41 PST 2014


On Thu, 2014-10-09 at 11:29 +0000, Sag Academy via Digitalmars-d-learn
wrote:
> On Thursday, 9 October 2014 at 10:10:20 UTC, Konstantin wrote:
> >> Are you looking for parallel? 
> >> http://dlang.org/library/std/parallelism/parallel.html
> >
> > I have seen this, but I'm not sure how to use it.
> >
> > Maybe:
> >
> > float[][] maps = new float[#threads][resolution * resolution];
> >
> > foreach(i, ref elem; parallel(maps)){
> >     elem = generateTerrain(...);
> > }
> >
> > Does this look right?
> 
> Yeah, it is.

Or maybe not. The code above is fine per se, but only tackles the
generation phase, there will be later phases. It may be that other parts
of http://dlang.org/library/std/parallelism.html used slightly
differently would be better for describing more of the problem. taskPool
has a lot of interesting capabilities, including parallel reduce which
gives a full map–reduce type scatter–gather approach: OP did mention
that there was a generation then integration activity overall.

Of course, if absolute performance is required things get a bit more
tricky avoiding overheads.

-- 
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/20141102/989a1461/attachment.sig>


More information about the Digitalmars-d-learn mailing list