Parallel array processing in C#

arrays, c#

Solution

I suggest using Parallel Linq (PLinq) for this

int[] source = ...

int count = source
  .AsParallel()  // comment this out if you want sequential version
  .Count(item => item > 240);

Problem

I have an array of 921600 numbers between 0 and 255. I need to check each number whether it's above a threshold or not. Is it possible to check the first- and second half of the array at the same time, to cut down on run time? What I mean is, is it possible to run the following two for loops in parallel? ``` for(int i = 0; i < 921600 / 2; i++) { if(arr[i] > 240) counter++; } for(int j = 921600 / 2; j < 921600; j++) { if(arr[j] > 240) counter++; } ``` Thank you in advance!

Original source