challenge #3 - Parallel for loop

janderson askme at me.com
Fri Jan 26 09:37:37 PST 2007


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?

-Joel



More information about the Digitalmars-d mailing list