This project is read-only.

Parallelizing multiple caclulations

Mar 3, 2014 at 7:58 PM
Hello,

I need help. I want to parallelize thousands of calculations with the same parsed function but different variable values. At the Moment, it works perfect, with one thread, but I want to compute it with Parallel.ForEach with the Task Parallel Library. For Example, the function f(x,y)=cos(x+y),
there is a range from X/Y -100,+100, and the step is 0.1. The problem is, if I using it with Parallel.ForEach (... x-range colleciton), the results are not correct. I mean the problem is setting of the parameter for x and y. Could you help.

Thank you
Ronny
Mar 4, 2014 at 9:08 AM
For Example this one,
        Parallel.For(0, 100, (i) =>
        {

            expParams.Parameters["x"] = i;
            var c = sum.Calculate(expParams);
            Console.WriteLine("x=" + i + ", " + c);
        });
It calculates wrong, because the setting of x and the calculute-method are sometimes not in one
thread. If I use the lock keyword, the calculation would never be parallized. maybe you can fix this issue
with a threadsafe ExpressionParameters-Dictionary,

Best Regards
Ronny
Mar 5, 2014 at 9:40 AM
You can use a different ExpressionParameters for each thread or use a "pool" of ExpressionParameters (4 thread - 4 dictionaries)
Mar 5, 2014 at 12:41 PM
Thank you.
I have solved it with different expressionparameters.