Answer the question
In order to leave comments, you need to log in
Where does the contents of the array go when passing it to an intermediate method?
There is a method producing some arithmetic operations. In the first half of the method, an array x is calculated, consisting of numbers arranged in ascending order, which is passed to the intermediate method for subsequent calculations.
The code is something like this:
{
...
//Это выходные параметры
double[] L;
double[] V;
...
for (int i = 2; i < n; i++)
{
FormANk(V, ref d, ref e, ref a, L);
Value(d, e, a, i + 1, ref L, ref V, epsilon);
}
//t1
if (need)
{
vr = EV(dA, eA, L);
...
}
lam = L;
vec = v;
}
static void Value(double[] d, double[] e, double[] A, int n, ref double[] l, ref double[] v, double epsilon)
{
double[] L = new double[n];
double[] V;
//p1
Parallel.For(0, n - 2, i =>
{
Interlocked.Exchange(ref L[i + 1], EVIn(d, i, A, epsilon));
});
EVOut(d, A, ref L);
V = EVs(A, d, L);
l = L;
v = V;
}
private static double[,] EV(double[] d, double[] e, double[] L)
{
//t2
int n = d.Length;
double[,] res = new double[n, n];
//p2
Parallel.For(0, n, j =>
{
Interlocked.Exchange(ref res[0, j], 1.0d);
Interlocked.Exchange(ref res[1, j], (L[j] - d[0]) * res[0, j] / e[0]);
for (int i = 2; i < n; i++)
{
Interlocked.Exchange(ref res[i, j], ((L[j] - d[i - 1]) * res[i - 1, j] - e[i - 2] * res[i - 2, j]) / e[i - 1]); ;
}
});
Norm(res);
return res;
}
Answer the question
In order to leave comments, you need to log in
Try playing around with ParallelOptions.MaxDegreeOfParallelism and make sure that Parallel.For evaluates to positive.
An error in the code was found and does not lie in Parallel.For itself. However, the randomness of execution / non-execution of the code remained unclear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question