Browse Source

fixed a problem were Parallel Invoke and Select where ignoring threading options from Control, there is still an issue with recursively calling invoke.

la-knuth
Marcus Cuda 16 years ago
parent
commit
39ea72370a
  1. 3
      src/MathNet.Numerics.5.1.ReSharper
  2. 16
      src/Numerics/Threading/CommonParallel.cs

3
src/MathNet.Numerics.5.1.ReSharper

@ -82,7 +82,8 @@ Wikipedia
kronecker kronecker
blocksize blocksize
ipiv ipiv
dll</UserWords> dll
Silverlight</UserWords>
</CustomDictionary> </CustomDictionary>
</Dictionaries> </Dictionaries>
</CustomDictionaries> </CustomDictionaries>

16
src/Numerics/Threading/CommonParallel.cs

@ -327,11 +327,17 @@ namespace MathNet.Numerics.Threading
/// Executes each of the provided actions inside a discrete, asynchronous task. /// Executes each of the provided actions inside a discrete, asynchronous task.
/// </summary> /// </summary>
/// <param name="actions">An array of actions to execute.</param> /// <param name="actions">An array of actions to execute.</param>
/// <exception cref="ArgumentException">The actions array contains a null element.</exception> /// <exception cref="ArgumentException">The actions array contains a <c>null</c> element.</exception>
/// <exception cref="AggregateException">An action threw an exception.</exception> /// <exception cref="AggregateException">An action threw an exception.</exception>
public static void Invoke(params Action[] actions) public static void Invoke(params Action[] actions)
{ {
Parallel.Invoke(actions); var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.Invoke(
new ParallelOptions
{
MaxDegreeOfParallelism = maxThreads
},
actions);
} }
/// <summary> /// <summary>
@ -361,9 +367,10 @@ namespace MathNet.Numerics.Threading
} }
}); });
#else #else
var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.ForEach( Parallel.ForEach(
Partitioner.Create(fromInclusive, toExclusive), Partitioner.Create(fromInclusive, toExclusive),
new ParallelOptions { MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads }, new ParallelOptions { MaxDegreeOfParallelism = maxThreads },
() => 0.0, () => 0.0,
(range, loop, localData) => (range, loop, localData) =>
{ {
@ -413,9 +420,10 @@ namespace MathNet.Numerics.Threading
} }
}); });
#else #else
var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.ForEach( Parallel.ForEach(
Partitioner.Create(fromInclusive, toExclusive), Partitioner.Create(fromInclusive, toExclusive),
new ParallelOptions { MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads }, new ParallelOptions { MaxDegreeOfParallelism = maxThreads },
() => 0.0f, () => 0.0f,
(range, loop, localData) => (range, loop, localData) =>
{ {

Loading…
Cancel
Save