static double ParallelPartitionerPi() { double sum = 0.0; double step = 1.0 / (double)num_steps; object monitor = new object(); Parallel.ForEach(Partitioner.Create(0, num_steps), () => 0.0, (range, state, local) => { for (int i = range.Item1; i < range.Item2; i++) { double x = (i + 0.5) * step; local += 4.0 / (1.0 + x * x); } return local; }, local => { lock (monitor) sum += local; }); return step * sum; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)