Advertisement
Guest User

Loop to parallelize

a guest
Feb 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             // Calculation of image statistics
  2.             // We could use LINQ to get Min and Max easily but this way we do it all
  3.             // in a single passege through image matrix
  4.             Stopwatch stopWatch = new Stopwatch();
  5.             stopWatch.Start();
  6.             UInt16 tempMin = (UInt16)(Math.Pow(2, mfvm.cameras[openCamIndex].bitDepth) - 1);
  7.             UInt16 tempMax = acquisition.frameDataShorts.AsParallel().Max();
  8.             UInt64 tempSum = 0;
  9.  
  10.             stopWatch.Stop();
  11.             for (int i = 0; i < acquisition.frameDataShorts.Length; i++)
  12.             {
  13.                 if (acquisition.frameDataShorts[i] < tempMin)
  14.                     tempMin = acquisition.frameDataShorts[i];
  15.  
  16.                 if (acquisition.frameDataShorts[i] > tempMax)
  17.                     tempMax = acquisition.frameDataShorts[i];
  18.  
  19.                 tempSum += acquisition.frameDataShorts[i];
  20.             }
  21.  
  22.             stopWatch.Stop();
  23.             // Get the elapsed time as a TimeSpan value.
  24.             TimeSpan ts = stopWatch.Elapsed;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement