- Timestamp:
- 03/20/13 16:51:58 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ParallelEngine/3.3/ParallelEngine.cs
r7259 r9323 37 37 public class ParallelEngine : Engine { 38 38 private CancellationToken cancellationToken; 39 private ParallelOptions parallelOptions; 40 41 [Storable(DefaultValue = -1)] 42 private int degreeOfParallelism; 43 public int DegreeOfParallelism { 44 get { return degreeOfParallelism; } 45 set { 46 if (degreeOfParallelism != value) { 47 degreeOfParallelism = value; 48 OnDegreeOfParallelismChanged(); 49 } 50 } 51 } 39 52 40 53 [StorableConstructor] 41 54 protected ParallelEngine(bool deserializing) : base(deserializing) { } 42 protected ParallelEngine(ParallelEngine original, Cloner cloner) : base(original, cloner) { } 55 protected ParallelEngine(ParallelEngine original, Cloner cloner) 56 : base(original, cloner) { 57 this.DegreeOfParallelism = original.DegreeOfParallelism; 58 } 43 59 public ParallelEngine() : base() { } 44 60 … … 47 63 } 48 64 65 public event EventHandler DegreeOfParallelismChanged; 66 protected void OnDegreeOfParallelismChanged() { 67 var handler = DegreeOfParallelismChanged; 68 if (handler != null) handler(this, EventArgs.Empty); 69 } 70 71 49 72 protected override void Run(CancellationToken cancellationToken) { 50 73 this.cancellationToken = cancellationToken; 74 parallelOptions = new ParallelOptions(); 75 parallelOptions.MaxDegreeOfParallelism = DegreeOfParallelism; 51 76 Run(ExecutionStack); 52 77 } … … 65 90 coll = (OperationCollection)next; 66 91 if (coll.Parallel) { 67 Task[] tasks = new Task[coll.Count];68 92 Stack<IOperation>[] stacks = new Stack<IOperation>[coll.Count]; 69 93 for (int i = 0; i < coll.Count; i++) { 70 94 stacks[i] = new Stack<IOperation>(); 71 95 stacks[i].Push(coll[i]); 72 tasks[i] = Task.Factory.StartNew(Run, stacks[i], cancellationToken);73 96 } 74 97 try { 75 Task.WaitAll(tasks);98 Parallel.ForEach(stacks, parallelOptions, Run); 76 99 } 77 100 catch (AggregateException ex) {
Note: See TracChangeset
for help on using the changeset viewer.