
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 (... xrange 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



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 calculutemethod 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 ExpressionParametersDictionary,
Best Regards
Ronny



You can use a different ExpressionParameters for each thread or use a "pool" of ExpressionParameters (4 thread  4 dictionaries)



Thank you.
I have solved it with different expressionparameters.

