challenge #3 - Parallel for loop

Sean Kelly sean at f4.ca
Fri Jan 26 09:45:50 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
> }
> 
> //Example 2
> int sum = 0;
> for_parallel(int a; a<array.length; ++a) //These could be anything
> {
>   sum += array[a];   //This could be anything
> }
> 
> 1) The call syntax is a simple generic one statement.
> 2) It needs to represent a foreach/for-loop as close as possible, 
> although it doesn't need to look like a D foreach/for-loop.
> 3) It needs to handle things like adding all the parts in an array (this 
> is the difficult part).
> 4) Since foreach_parallel always works on an array, you may take some 
> concessions for this loop, taking the array of operation into account 
> (ie, you may split the array).
> 5) If we can't do it, what syntax would you recommend to close this gap?

See:

http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D.announce&artnum=5015

This could also be done in user code however.  The only real danger is 
that if more than one of the parallel threads throws an exception then 
the application must terminate.


Sean



More information about the Digitalmars-d mailing list