Wizwert / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

AForge.Parallel.For per thread state #172

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello
Below I am sending example code taken from microsoft's .net4.0 which I would 
like to run with AForge.Parallel.For, the main feature i believe may bring 
benefit to the project is possibility of using state attached to each thread 
executing loop which significantly reduces the need of using locks         

/// <summary>Estimates the value of PI using a Parallel.For.</summary>
        static double ParallelPi()
        {
            double sum = 0.0;
            double step = 1.0 / (double)num_steps;
            object monitor = new object();
            Parallel.For(0, num_steps, () => 0.0, (i, state, local) =>
            {
                double x = (i + 0.5) * step;
                return local + 4.0 / (1.0 + x * x);
            }, local => { lock (monitor) sum += local; });
            return step * sum;
        }

I've tried mono but their implementation runs aprox. 100 times slower than 
.net4.0 !
(even 50 slower than synchronous version)

Best regards,
Mariusz Krej

Original issue reported on code.google.com by mariusz....@gmail.com on 8 Nov 2010 at 10:25

GoogleCodeExporter commented 8 years ago
There are no plans to extend Parallel.For() support to mimic MS implementation. 
Current implementation was done simple enough and usable enough for many 
applications (not most or all).

Original comment by andrew.k...@gmail.com on 8 Feb 2012 at 10:09