Parallelism Map and Reduce

Zardoz luis.panadero at gmail.com
Tue Dec 11 02:53:18 PST 2012


Hi! Now I have this code :

       auto acelByObjs = map!( (Entity o) {
           Vector3 r = o.pos[0] - pos[0];
           return r * (o.mass / pow((r.sq_length + epsilon2), 
1.5));
           } )(objects);
       newAcel = reduce!("a + b")(acelByObjs);

It works very well with the std.algorithm Map and Reduce but when 
I try to use std.parallelism versions of it, parallel Map give me 
this compilataion errors :

entity.d(63): Error: template instance map!(delegate @system 
Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
) cannot use local '__lambda3' as parameter to non-global 
template map(functions...)
/usr/include/dmd/phobos/std/parallelism.d(1969): Error: function 
std.parallelism.TaskPool.map!(delegate @system Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
).map!(Entity[]).map.Map.fillBuf cannot access frame of function 
entity.Entity.CalcAcel
/usr/include/dmd/phobos/std/parallelism.d(1974): Error: template 
instance amap!(delegate @system Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
) cannot use local '__lambda3' as parameter to non-global 
template amap(functions...)
/usr/include/dmd/phobos/std/parallelism.d(1675): Error: function 
std.parallelism.TaskPool.amap!(delegate @system Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
).amap!(Entity[],ulong,Vector3[]).amap cannot access frame of 
function entity.Entity.CalcAcel
/usr/include/dmd/phobos/std/parallelism.d(1706): Error: function 
std.parallelism.TaskPool.amap!(delegate @system Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
).amap!(Entity[],ulong,Vector3[]).amap.doIt cannot access frame 
of function entity.Entity.CalcAcel
/usr/include/dmd/phobos/std/parallelism.d(1974): Error: template 
instance std.parallelism.TaskPool.amap!(delegate @system 
Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
).amap!(Entity[],ulong,Vector3[]) error instantiating
entity.d(66):        instantiated from here: map!(Entity[])
entity.d(66): Error: template instance 
std.parallelism.TaskPool.map!(delegate @system Vector3(Entity o)
{
Vector3 r = o.pos[0LU].opBinary(this.pos[0LU]);
return r.opBinary(o.mass / pow(r.sq_length() + epsilon2,1.5));
}
).map!(Entity[]) error instantiating
make: *** [predSim] Error 1

Plus , if  I only the parallel Reduce, It takes more around 9 
times more that the serial versión for an array of 30 elements!
I tested before parallel reduction with the example code of 
calculating PI, in my quad core machine taking 4 times less that 
the serial versión... I will try with a bigger array but using 
parallel foreach takes less times that serial versión, so I don't 
think that the these big extra time comes for making the theads. 
Any other idea of what can be hapening here ?


More information about the Digitalmars-d-learn mailing list