Changeset 9323


Ignore:
Timestamp:
03/20/13 16:51:58 (6 years ago)
Author:
mkommend
Message:

#2024: Changed parallel engine to use parallel.foreach instead of spawning task manually to enable more options for parallelization.

Location:
trunk/sources
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r9179 r9323  
    2828    {B7FA451C-26BF-4EE5-8E0E-BECAADA5B8E9} = {B7FA451C-26BF-4EE5-8E0E-BECAADA5B8E9}
    2929    {E226881D-315F-423D-B419-A766FE0D8685} = {E226881D-315F-423D-B419-A766FE0D8685}
     30    {D34A7620-3E23-40D9-8647-637BE901F271} = {D34A7620-3E23-40D9-8647-637BE901F271}
    3031    {F62BCD22-FB83-4444-9401-8031C2487A86} = {F62BCD22-FB83-4444-9401-8031C2487A86}
    3132    {E0B45023-CB84-48A1-A1B7-8295B64B7BAD} = {E0B45023-CB84-48A1-A1B7-8295B64B7BAD}
     
    376377Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.Instances.Scheduling-3.3", "HeuristicLab.Problems.Instances.Scheduling\3.3\HeuristicLab.Problems.Instances.Scheduling-3.3.csproj", "{9D792B6D-836B-46DC-9D69-50B4B1E7B87F}"
    377378EndProject
     379Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.ParallelEngine.Views", "HeuristicLab.ParallelEngine.Views\3.3\HeuristicLab.ParallelEngine.Views.csproj", "{D34A7620-3E23-40D9-8647-637BE901F271}"
     380EndProject
    378381Global
    379382  GlobalSection(SolutionConfigurationPlatforms) = preSolution
     
    386389  EndGlobalSection
    387390  GlobalSection(ProjectConfigurationPlatforms) = postSolution
     391    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     392    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
     393    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x64.ActiveCfg = Debug|x64
     394    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x64.Build.0 = Debug|x64
     395    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x86.ActiveCfg = Debug|x86
     396    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x86.Build.0 = Debug|x86
     397    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
     398    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|Any CPU.Build.0 = Release|Any CPU
     399    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x64.ActiveCfg = Release|x64
     400    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x64.Build.0 = Release|x64
     401    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x86.ActiveCfg = Release|x86
     402    {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x86.Build.0 = Release|x86
    388403    {94186A6A-5176-4402-AE83-886557B53CCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    389404    {94186A6A-5176-4402-AE83-886557B53CCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
     
    506521    {6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6}.Release|x86.ActiveCfg = Release|x86
    507522    {6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6}.Release|x86.Build.0 = Release|x86
    508     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    509     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
    510     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x64.ActiveCfg = Debug|x64
    511     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x64.Build.0 = Debug|x64
    512     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x86.ActiveCfg = Debug|x86
    513     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Debug|x86.Build.0 = Debug|x86
    514     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
    515     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|Any CPU.Build.0 = Release|Any CPU
    516     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x64.ActiveCfg = Release|x64
    517     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x64.Build.0 = Release|x64
    518     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x86.ActiveCfg = Release|x86
    519     {B1DCDECA-B56E-41D5-9850-EF0D3A77DEAF}.Release|x86.Build.0 = Release|x86
    520523    {EE2034D9-6E27-48A1-B855-42D45F69A4FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    521524    {EE2034D9-6E27-48A1-B855-42D45F69A4FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
     
    18261829    {9D792B6D-836B-46DC-9D69-50B4B1E7B87F}.Release|x86.ActiveCfg = Release|x86
    18271830    {9D792B6D-836B-46DC-9D69-50B4B1E7B87F}.Release|x86.Build.0 = Release|x86
     1831    {D34A7620-3E23-40D9-8647-637BE901F271}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     1832    {D34A7620-3E23-40D9-8647-637BE901F271}.Debug|Any CPU.Build.0 = Debug|Any CPU
     1833    {D34A7620-3E23-40D9-8647-637BE901F271}.Debug|x64.ActiveCfg = Debug|x64
     1834    {D34A7620-3E23-40D9-8647-637BE901F271}.Debug|x64.Build.0 = Debug|x64
     1835    {D34A7620-3E23-40D9-8647-637BE901F271}.Debug|x86.ActiveCfg = Debug|x86
     1836    {D34A7620-3E23-40D9-8647-637BE901F271}.Debug|x86.Build.0 = Debug|x86
     1837    {D34A7620-3E23-40D9-8647-637BE901F271}.Release|Any CPU.ActiveCfg = Release|Any CPU
     1838    {D34A7620-3E23-40D9-8647-637BE901F271}.Release|Any CPU.Build.0 = Release|Any CPU
     1839    {D34A7620-3E23-40D9-8647-637BE901F271}.Release|x64.ActiveCfg = Release|x64
     1840    {D34A7620-3E23-40D9-8647-637BE901F271}.Release|x64.Build.0 = Release|x64
     1841    {D34A7620-3E23-40D9-8647-637BE901F271}.Release|x86.ActiveCfg = Release|x86
     1842    {D34A7620-3E23-40D9-8647-637BE901F271}.Release|x86.Build.0 = Release|x86
    18281843  EndGlobalSection
    18291844  GlobalSection(SolutionProperties) = preSolution
  • trunk/sources/HeuristicLab.ParallelEngine/3.3/ParallelEngine.cs

    r7259 r9323  
    3737  public class ParallelEngine : Engine {
    3838    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    }
    3952
    4053    [StorableConstructor]
    4154    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    }
    4359    public ParallelEngine() : base() { }
    4460
     
    4763    }
    4864
     65    public event EventHandler DegreeOfParallelismChanged;
     66    protected void OnDegreeOfParallelismChanged() {
     67      var handler = DegreeOfParallelismChanged;
     68      if (handler != null) handler(this, EventArgs.Empty);
     69    }
     70
     71
    4972    protected override void Run(CancellationToken cancellationToken) {
    5073      this.cancellationToken = cancellationToken;
     74      parallelOptions = new ParallelOptions();
     75      parallelOptions.MaxDegreeOfParallelism = DegreeOfParallelism;
    5176      Run(ExecutionStack);
    5277    }
     
    6590          coll = (OperationCollection)next;
    6691          if (coll.Parallel) {
    67             Task[] tasks = new Task[coll.Count];
    6892            Stack<IOperation>[] stacks = new Stack<IOperation>[coll.Count];
    6993            for (int i = 0; i < coll.Count; i++) {
    7094              stacks[i] = new Stack<IOperation>();
    7195              stacks[i].Push(coll[i]);
    72               tasks[i] = Task.Factory.StartNew(Run, stacks[i], cancellationToken);
    7396            }
    7497            try {
    75               Task.WaitAll(tasks);
     98              Parallel.ForEach(stacks, parallelOptions, Run);
    7699            }
    77100            catch (AggregateException ex) {
Note: See TracChangeset for help on using the changeset viewer.