www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Map and Spawn don't mix?

reply Russel Winder <russel russel.org.uk> writes:
If I do:

  auto tasks =3D new Tid[numberOfTasks] ; =20
  foreach ( i ; 0 .. numberOfTasks ) { tasks[i] =3D spawn ( & partialSum , =
thisTid , i , sliceSize , delta ) ; }

everything workls as desired, I get parallelism and appropriate scaling.
However if I try:

  auto tasks =3D map ! ( ( i ) { return spawn ( & partialSum , thisTid , i =
, sliceSize , delta ) ; } ) ( iota ( numberOfTasks ) ) ;

the code runs but everything is serialized, no parallelism, no speed up.

I would say this is a bug, but perhaps it is a consequence of the way map w=
orks?

--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder ekiga.n=
et
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
Mar 06 2011
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/6/11 10:44 AM, Russel Winder wrote:
 If I do:

    auto tasks = new Tid[numberOfTasks] ;
    foreach ( i ; 0 .. numberOfTasks ) { tasks[i] = spawn (&  partialSum ,
thisTid , i , sliceSize , delta ) ; }

 everything workls as desired, I get parallelism and appropriate scaling.
 However if I try:

    auto tasks = map ! ( ( i ) { return spawn (&  partialSum , thisTid , i ,
sliceSize , delta ) ; } ) ( iota ( numberOfTasks ) ) ;

 the code runs but everything is serialized, no parallelism, no speed up.

 I would say this is a bug, but perhaps it is a consequence of the way map
works?
I doubt the code ever runs - map is lazy. Andrei
Mar 06 2011