I have simple code
for( int i = 0 ; i < arr.GetLength(0) ; i++)
{
for( int j = 0 ; j < arr.GetLength(1) ; j++)
{
arr[i, j ] = 0;
}
}
I need to make this code to be very fast – so i want to use the Tasks.Parallel.For
What will be the most fast and effecint way to use the Parallel.For ?
It can be like this
Parallel.for( int i = 0 ; i < arr.GetLength(0) ; i++)
{
Parallel.for( int j = 0 ; j < arr.GetLength(1) ; j++)
{
arr[i, j ] = 0;
}
}
or just use one Parallel.for ?
You would be better off using the
Parallel.for(...)on the outer loop only.The idea being that you would have as many cores in parallel execute the inner loop’s iterations.