I am using someone else's .NET 4 open source smoothed particle hydrodynamics code and I'm trying to convert it for a Unity project which you can only count on to be up to .NET 2 standards. Unfortunately the code uses the Parallels class (which is awesome!) but he used one of the more obscure overloads. Can anyone see a good way to achieve the same thing in .NET 2 without a huge performance hit?
Parallel.For(
0,
_numActiveParticles,
() => new Vector2[MAX_PARTICLES],
(i, state, accumulatedDelta) => calculateForce(_activeParticles[i], accumulatedDelta),
(accumulatedDelta) =>
{
lock (_calculateForcesLock)
{
for (int i = _numActiveParticles - 1; i >= 0; i--)
{
int index = _activeParticles[i];
_delta[index] += accumulatedDelta[index] / MULTIPLIER;
}
}
}
);
I think this is what the code does (non threaded):
for (int i = 0; i < _numActiveParticles; i++)
{
Vector2[] temp = new Vector2[MAX_PARTICLES];
temp = calculateForce(_activeParticles[i], temp);
for (int k = _numActiveParticles - 1; k >= 0; k--)
{
int index = _activeParticles[k];
_delta[index] += temp[index] / MULTIPLIER;
}
}