Changeset 5136


Ignore:
Timestamp:
12/20/10 19:05:33 (10 years ago)
Author:
cneumuel
Message:

#1347

  • worked on HiveEngine
Location:
branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/HeuristicLab.HiveEngine-3.3.csproj

    r5134 r5136  
    99    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    11     <RootNamespace>HeuristicLab.HiveParallelEngine</RootNamespace>
    12     <AssemblyName>HeuristicLab.HiveParallelEngine-3.3</AssemblyName>
     11    <RootNamespace>HeuristicLab.HiveEngine</RootNamespace>
     12    <AssemblyName>HeuristicLab.HiveEngine-3.3</AssemblyName>
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
     
    3333  </PropertyGroup>
    3434  <ItemGroup>
     35    <Reference Include="HeuristicLab.Clients.Common-3.3">
     36      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Clients.Common-3.3.dll</HintPath>
     37    </Reference>
     38    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     39      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath>
     40    </Reference>
    3541    <Reference Include="HeuristicLab.Common-3.3">
    3642      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>
     43    </Reference>
     44    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     45      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common.Resources-3.3.dll</HintPath>
    3746    </Reference>
    3847    <Reference Include="HeuristicLab.Core-3.3">
     
    4554      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    4655    </Reference>
     56    <Reference Include="HeuristicLab.SequentialEngine-3.3">
     57      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath>
     58    </Reference>
    4759    <Reference Include="System" />
    4860    <Reference Include="System.Core" />
     61    <Reference Include="System.Drawing" />
    4962    <Reference Include="System.Xml.Linq" />
    5063    <Reference Include="System.Data.DataSetExtensions" />
     
    5366  </ItemGroup>
    5467  <ItemGroup>
     68    <Compile Include="ScopeMergeException.cs" />
    5569    <None Include="Properties\AssemblyInfo.cs.frame" />
    5670    <None Include="HeuristicLabHiveEnginePlugin.cs.frame" />
    5771    <Compile Include="HeuristicLabHiveEnginePlugin.cs" />
    5872    <Compile Include="HiveEngine.cs" />
     73    <Compile Include="OperationJob.cs" />
    5974    <Compile Include="Properties\AssemblyInfo.cs" />
     75  </ItemGroup>
     76  <ItemGroup>
     77    <ProjectReference Include="..\..\HeuristicLab.DataAccess\3.3\HeuristicLab.DataAccess-3.3.csproj">
     78      <Project>{9076697B-C151-46CD-95BC-1D059492B478}</Project>
     79      <Name>HeuristicLab.DataAccess-3.3</Name>
     80    </ProjectReference>
     81    <ProjectReference Include="..\..\HeuristicLab.Hive.Contracts\3.3\HeuristicLab.Hive.Contracts-3.3.csproj">
     82      <Project>{134F93D7-E7C8-4ECD-9923-7F63259A60D8}</Project>
     83      <Name>HeuristicLab.Hive.Contracts-3.3</Name>
     84    </ProjectReference>
     85    <ProjectReference Include="..\..\HeuristicLab.Hive.ExperimentManager\3.3\HeuristicLab.Hive.ExperimentManager-3.3.csproj">
     86      <Project>{A84C0A25-13D0-40A6-924F-53556D9691DC}</Project>
     87      <Name>HeuristicLab.Hive.ExperimentManager-3.3</Name>
     88    </ProjectReference>
     89    <ProjectReference Include="..\..\HeuristicLab.Hive.JobBase\3.3\HeuristicLab.Hive.JobBase-3.3.csproj">
     90      <Project>{21187322-52DD-4243-80A4-A85F0263E63B}</Project>
     91      <Name>HeuristicLab.Hive.JobBase-3.3</Name>
     92    </ProjectReference>
    6093  </ItemGroup>
    6194  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/HeuristicLabHiveEnginePlugin.cs.frame

    r5134 r5136  
    55using HeuristicLab.PluginInfrastructure;
    66
    7 namespace HiveParallelEngine {
     7namespace HeuristicLab.HiveEngine {
    88  /// <summary>
    9   /// Plugin class for HeuristicLab.HiveParallelEngine plugin.
     9  /// Plugin class for HeuristicLab.HiveEngine plugin.
    1010  /// </summary>
    11   [Plugin("HeuristicLab.SequentialEngine", "3.3.2.$WCREV$")]
    12   [PluginFile("HeuristicLab.SequentialEngine-3.3.dll", PluginFileType.Assembly)]
     11  [Plugin("HeuristicLab.HiveEngine", "3.3.2.$WCREV$")]
     12  [PluginFile("HeuristicLab.HiveEngine-3.3.dll", PluginFileType.Assembly)]
     13  [PluginDependency("HeuristicLab.Clients.Common", "3.3")]
     14  [PluginDependency("HeuristicLab.Collections", "3.3")]
    1315  [PluginDependency("HeuristicLab.Common", "3.3")]
     16  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    1417  [PluginDependency("HeuristicLab.Core", "3.3")]
     18  [PluginDependency("HeuristicLab.DataAccess", "3.3")]
     19  [PluginDependency("HeuristicLab.Hive.Contracts", "3.3")]
     20  [PluginDependency("HeuristicLab.Hive.ExperimentManager", "3.3")]
     21  [PluginDependency("HeuristicLab.Hive.JobBase", "3.3")]
    1522  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    16   class HeuristicLabHiveParallelEnginePlugin {
     23  [PluginDependency("HeuristicLab.SequentialEngine", "3.3")]
     24  public class HeuristicLabHiveEnginePlugin : PluginBase {
    1725  }
    1826}
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/HiveEngine.cs

    r5134 r5136  
    66using HeuristicLab.Core;
    77using HeuristicLab.Common;
     8using HeuristicLab.Hive.Contracts.Interfaces;
     9using HeuristicLab.Clients.Common;
     10using HeuristicLab.Hive.ExperimentManager;
     11using HeuristicLab.Hive.Contracts.BusinessObjects;
     12using HeuristicLab.PluginInfrastructure;
     13using HeuristicLab.Hive.Contracts.ResponseObjects;
     14using System.Threading;
    815
    9 namespace HeuristicLab.HiveParallelEngine {
     16namespace HeuristicLab.HiveEngine {
    1017  /// <summary>
    1118  /// Represents an engine that executes operations which can be executed in parallel on the hive
     
    2027    [StorableConstructor]
    2128    protected HiveEngine(bool deserializing) : base(deserializing) { }
    22     protected HiveEngine(HiveEngine original, Cloner cloner) : base(original, cloner) {
     29    protected HiveEngine(HiveEngine original, Cloner cloner)
     30      : base(original, cloner) {
    2331    }
    2432    public override IDeepCloneable Clone(Cloner cloner) {
     
    3240      OperationCollection coll = next as OperationCollection;
    3341
    34       if (coll.Parallel) {
    35                
    36       } else {
    37         while (coll != null) {
     42      while (coll != null) {
     43        if (coll.Parallel) {
     44          IScope scope = ((IAtomicOperation)coll.Where(x => x is IAtomicOperation).First()).Scope;
     45          IEnumerable<IOperation> finishedOperations = ExecuteOnHive(coll.Select(op => new OperationJob(op)));
     46          foreach (IOperation op in finishedOperations) {
     47            ReIntegrateScope(scope, op);
     48          }
     49        } else {
    3850          for (int i = coll.Count - 1; i >= 0; i--)
    3951            ExecutionStack.Push(coll[i]);
    40           next = ExecutionStack.Count > 0 ? ExecutionStack.Pop() : null;
    41           coll = next as OperationCollection;
    4252        }
     53        next = ExecutionStack.Count > 0 ? ExecutionStack.Pop() : null;
     54        coll = next as OperationCollection;
    4355      }
    4456
     
    6173    }
    6274
     75    private static void ReIntegrateScope(IScope scope, IOperation operation) {
     76      if (operation is IAtomicOperation) {
     77        MergeScopes(scope, ((IAtomicOperation)operation).Scope);
     78      } else if (operation is OperationCollection) {
     79        foreach (IOperation op in (OperationCollection)operation) {
     80          ReIntegrateScope(scope, op);
     81        }
     82      }
     83    }
     84
     85    private static void MergeScopes(IScope target, IScope source) {
     86      foreach (IVariable variable in source.Variables) {
     87        if (target.Variables.ContainsKey(variable.Name)) {
     88          if (target.Variables[variable.Name] != source.Variables[variable.Name]) {
     89            // problem: ResultCollection are not equal altough they contain the same values.
     90            //             - either implement ResultCollection.Equals, or consider ResultCollection as special case here
     91            //throw new ScopeMergeException(string.Format("Variable {0} already exists in target scope and has a different value ({1}, {2}).", variable.Name, target.Variables[variable.Name].Value, variable.Value));
     92          }
     93        } else {
     94          target.Variables.Add(variable);
     95        }
     96      }
     97
     98      //this is not useful on the parentscope of the initial scope
     99      //foreach (IScope subScope in source.SubScopes) {
     100      //  target.SubScopes.Add(subScope);
     101      //}
     102
     103      if (target.Parent != null && source.Parent != null)
     104        MergeScopes(target.Parent, source.Parent);
     105    }
     106
     107
     108    private IEnumerable<IOperation> TestExecuteOnHive(IEnumerable<OperationJob> operationJobs) {
     109      //var clonedJobs = operationJobs.Select(x => (OperationJob)x.Clone()).ToArray();
     110      var results = new List<IOperation>();
     111
     112      foreach (var job in operationJobs) {
     113        job.Start();
     114        while (job.ExecutionState != Core.ExecutionState.Stopped) {
     115          Thread.Sleep(100);
     116        }
     117        results.Add(job.Operation);
     118      }
     119      return results;
     120    }
     121
     122    private IEnumerable<IOperation> ExecuteOnHive(IEnumerable<OperationJob> operationJobs) {
     123      IEnumerable<Guid> jobIds;
     124      JobResultList results;
     125
     126
     127      using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
     128        List<JobDto> jobs = new List<JobDto>();
     129        foreach (OperationJob operationJob in operationJobs) {
     130          var groups = new string[] { "HEAL" };
     131          SerializedJob serializedJob = new SerializedJob();
     132          serializedJob.SerializedJobData = SerializedJob.Serialize(operationJob);
     133          serializedJob.JobInfo = new JobDto();
     134          serializedJob.JobInfo.State = JobState.Offline;
     135          serializedJob.JobInfo.CoresNeeded = 1;
     136          serializedJob.JobInfo.PluginsNeeded = ApplicationManager.Manager.Plugins.Select(x => new HivePluginInfoDto { Name = x.Name, Version = x.Version }).ToList();
     137          ResponseObject<JobDto> response = service.Obj.AddJobWithGroupStrings(serializedJob, groups);
     138          jobs.Add(response.Obj);
     139        }
     140        jobIds = jobs.Select(x => x.Id);
     141        results = service.Obj.GetJobResults(jobIds).Obj;
     142      }
     143
     144      while (!results.All(
     145          x => x.State == JobState.Finished ||
     146          x.State == JobState.Failed ||
     147          x.State == JobState.Aborted)) {
     148        Thread.Sleep(5000);
     149        using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
     150          results = service.Obj.GetJobResults(jobIds).Obj;
     151        }
     152      }
     153
     154      // all finished
     155      List<OperationJob> finishedJobs = new List<OperationJob>();
     156      using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
     157        foreach (Guid jobId in jobIds) {
     158          SerializedJob serializedJob = service.Obj.GetLastSerializedResult(jobId).Obj;
     159          OperationJob operationJob = SerializedJob.Deserialize<OperationJob>(serializedJob.SerializedJobData);
     160          finishedJobs.Add(operationJob);
     161        }
     162      }
     163
     164      // delete jobs
     165      // TODO
     166
     167      return finishedJobs.Select(x => x.Operation);
     168    }
     169
    63170    public override void Pause() {
    64171      base.Pause();
Note: See TracChangeset for help on using the changeset viewer.