Changeset 6435
- Timestamp:
- 06/16/11 15:28:20 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine/3.4/HiveEngine.cs
r6426 r6435 38 38 public class HiveEngine : Engine { 39 39 private static object locker = new object(); 40 private static object logLocker = new object();41 40 private CancellationToken cancellationToken; 42 41 private bool firstRun = true; … … 74 73 } 75 74 76 // [Storable] -> HiveExperiment can't be storable, so RefreshableHiveExperiment can't be stored75 // HiveExperiment can't be storable, so RefreshableHiveExperiment can't be stored. But as previous runs are only informative it does not matter (only execution time on hive will be wrong because of that -> Todo) 77 76 private ItemCollection<RefreshableHiveExperiment> hiveExperiments = new ItemCollection<RefreshableHiveExperiment>(); 78 77 public ItemCollection<RefreshableHiveExperiment> HiveExperiments { … … 97 96 ResourceNames = "HEAL"; 98 97 Priority = 0; 98 this.log = new ThreadSafeLog(this.log); 99 99 } 100 100 … … 108 108 this.executionTimeOnHive = original.executionTimeOnHive; 109 109 this.IsPrivileged = original.IsPrivileged; 110 // this.hiveExperiments = cloner.Clone(original.hiveExperiments);do not clone hiveExperiments - otherwise they would be sent with every job110 // do not clone hiveExperiments - otherwise they would be sent with every job 111 111 } 112 112 public override IDeepCloneable Clone(Cloner cloner) { … … 150 150 151 151 next = executionStack.Pop(); 152 //bool isOpCollection = next is OperationCollection;153 //int collCount = isOpCollection ? ((OperationCollection)next).Count : 0;154 //string opName = !isOpCollection ? ((IAtomicOperation)next).Operator.Name : "OpCollection";155 156 152 if (next is OperationCollection) { 157 153 coll = (OperationCollection)next; 158 154 159 //bool isPMOEvaluator = coll.Count > 0 && coll.First() is HeuristicLab.Core.ExecutionContext && ((HeuristicLab.Core.ExecutionContext)coll.First()).Operator.GetType().Name == "PMOEvaluator";160 //bool isAlgorithmEvaluator = coll.Count > 0 && coll.First() is HeuristicLab.Core.ExecutionContext && ((HeuristicLab.Core.ExecutionContext)coll.First()).Operator.GetType().Name == "AlgorithmEvaluator";161 162 //if (coll.Parallel && isPMOEvaluator) {163 // Task[] tasks = new Task[coll.Count];164 // Stack<IOperation>[] stacks = new Stack<IOperation>[coll.Count];165 // for (int i = 0; i < coll.Count; i++) {166 // stacks[i] = new Stack<IOperation>();167 // stacks[i].Push(coll[i]);168 // tasks[i] = Task.Factory.StartNew(Run, stacks[i], cancellationToken);169 // }170 // try {171 // Task.WaitAll(tasks);172 // }173 // catch (AggregateException ex) {174 // OperationCollection remaining = new OperationCollection() { Parallel = true };175 // for (int i = 0; i < stacks.Length; i++) {176 // if (stacks[i].Count == 1)177 // remaining.Add(stacks[i].Pop());178 // if (stacks[i].Count > 1) {179 // OperationCollection ops = new OperationCollection();180 // while (stacks[i].Count > 0)181 // ops.Add(stacks[i].Pop());182 // remaining.Add(ops);183 // }184 // }185 // if (remaining.Count > 0) executionStack.Push(remaining);186 // throw ex;187 // }188 //} else if (coll.Parallel) {189 155 if (coll.Parallel) { 190 156 try { … … 230 196 231 197 if (operation.Operator.Breakpoint) { 232 LogMessage(string.Format("Breakpoint: {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName));198 log.LogMessage(string.Format("Breakpoint: {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName)); 233 199 Pause(); 234 200 } … … 273 239 /// <param name="jobs"></param> 274 240 private IScope[] ExecuteOnHive(RefreshableHiveExperiment refreshableHiveExperiment, EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) { 275 LogMessage(string.Format("Executing {0} operations on the hive.", jobs.Length));241 log.LogMessage(string.Format("Executing {0} operations on the hive.", jobs.Length)); 276 242 IScope[] scopes = new Scope[jobs.Length]; 277 243 object locker = new object(); … … 290 256 random.Reset(random.Next()); 291 257 } 292 HiveClient.StartExperiment((e) => { LogException(e); }, refreshableHiveExperiment);258 HiveClient.StartExperiment((e) => { log.LogException(e); }, refreshableHiveExperiment); 293 259 294 260 // do polling until experiment is finished and all jobs are downloaded … … 298 264 cancellationToken.ThrowIfCancellationRequested(); 299 265 } 300 LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableHiveExperiment.ToString(), refreshableHiveExperiment.HiveExperiment.ExecutionTime));266 log.LogMessage(string.Format("{0} finished (TotalExecutionTime: {1}).", refreshableHiveExperiment.ToString(), refreshableHiveExperiment.HiveExperiment.ExecutionTime)); 301 267 302 268 var failedJobs = hiveExperiment.HiveJobs.Where(x => x.Job.State == JobState.Failed); … … 317 283 } 318 284 catch (Exception e) { 319 LogException(e);285 log.LogException(e); 320 286 throw e; 321 287 } … … 372 338 }); 373 339 } 374 375 /// <summary>376 /// Threadsafe message logging377 /// </summary>378 private void LogMessage(string message) {379 lock (logLocker) {380 Log.LogMessage(message);381 }382 }383 384 /// <summary>385 /// Threadsafe exception logging386 /// </summary>387 private void LogException(Exception exception) {388 lock (logLocker) {389 Log.LogException(exception);390 }391 }392 393 // testfunction:394 //private IScope[] ExecuteLocally(EngineJob[] jobs, IScope parentScopeClone, CancellationToken cancellationToken) {395 // IScope[] scopes = new Scope[jobs.Length];396 // for (int i = 0; i < jobs.Length; i++) {397 // var serialized = PersistenceUtil.Serialize(jobs[i]);398 // var deserialized = PersistenceUtil.Deserialize<IJob>(serialized);399 // deserialized.Start();400 // while (deserialized.ExecutionState != ExecutionState.Stopped) {401 // Thread.Sleep(100);402 // }403 // var serialized2 = PersistenceUtil.Serialize(deserialized);404 // var deserialized2 = PersistenceUtil.Deserialize<EngineJob>(serialized2);405 // var newScope = ((IAtomicOperation)deserialized2.InitialOperation).Scope;406 // scopes[i] = newScope;407 // }408 // return scopes;409 //}410 340 } 411 341 }
Note: See TracChangeset
for help on using the changeset viewer.