challenge #3 - Parallel for loop
Benji Smith
dlanguage at benjismith.net
Fri Jan 26 12:58:58 PST 2007
janderson wrote:
> I would like to be able to run a for loop in parallel, using syntax like:
>
> //example 1
> int sum = 0;
> foreach_parallel(int a; array)
> {
> sum += array[a]; //This could be anything
> }
Isn't this really just a specialized case of Map/Reduce?
It's trivial, as long as the operations inside the loop are completely
associative. In other words:
A(B + C) == A(B) + A(C)
Since a summation satisfies the associativity requirements, then this
one is pretty trivial to implement.
But, not all operations are associative, and those ones won't be
trivially parallizable, without changing the algorithm.
Rather than focusing on a foreach_parallel construct, I'd be interested
in seeing a competition to implement the most elegant (syntax/semantics)
version of Map/Reduce. It'd be especially cool if a library
implementation of Map/Reduce could abstract away the details of whether
the function was mapped across multiples cores, cpus, or entire machines.
More details here:
http://labs.google.com/papers/mapreduce.html
http://en.wikipedia.org/wiki/MapReduce
--benji
More information about the Digitalmars-d
mailing list