Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/11 15:28:20 (14 years ago)
Author:
cneumuel
Message:

#1233

  • some cleanup
  • using ThreadSafeLog instead of synchronized methods
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine/3.4/HiveEngine.cs

    r6426 r6435  
    3838  public class HiveEngine : Engine {
    3939    private static object locker = new object();
    40     private static object logLocker = new object();
    4140    private CancellationToken cancellationToken;
    4241    private bool firstRun = true;
     
    7473    }
    7574
    76     // [Storable] -> HiveExperiment can't be storable, so RefreshableHiveExperiment can't be stored
     75    // 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)
    7776    private ItemCollection<RefreshableHiveExperiment> hiveExperiments = new ItemCollection<RefreshableHiveExperiment>();
    7877    public ItemCollection<RefreshableHiveExperiment> HiveExperiments {
     
    9796      ResourceNames = "HEAL";
    9897      Priority = 0;
     98      this.log = new ThreadSafeLog(this.log);
    9999    }
    100100
     
    108108      this.executionTimeOnHive = original.executionTimeOnHive;
    109109      this.IsPrivileged = original.IsPrivileged;
    110       // this.hiveExperiments = cloner.Clone(original.hiveExperiments); do not clone hiveExperiments - otherwise they would be sent with every job
     110      // do not clone hiveExperiments - otherwise they would be sent with every job
    111111    }
    112112    public override IDeepCloneable Clone(Cloner cloner) {
     
    150150
    151151        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 
    156152        if (next is OperationCollection) {
    157153          coll = (OperationCollection)next;
    158154
    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) {
    189155          if (coll.Parallel) {
    190156            try {
     
    230196
    231197          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));
    233199            Pause();
    234200          }
     
    273239    /// <param name="jobs"></param>
    274240    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));
    276242      IScope[] scopes = new Scope[jobs.Length];
    277243      object locker = new object();
     
    290256            random.Reset(random.Next());
    291257        }
    292         HiveClient.StartExperiment((e) => { LogException(e); }, refreshableHiveExperiment);
     258        HiveClient.StartExperiment((e) => { log.LogException(e); }, refreshableHiveExperiment);
    293259
    294260        // do polling until experiment is finished and all jobs are downloaded
     
    298264          cancellationToken.ThrowIfCancellationRequested();
    299265        }
    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));
    301267
    302268        var failedJobs = hiveExperiment.HiveJobs.Where(x => x.Job.State == JobState.Failed);
     
    317283      }
    318284      catch (Exception e) {
    319         LogException(e);
     285        log.LogException(e);
    320286        throw e;
    321287      }
     
    372338      });
    373339    }
    374 
    375     /// <summary>
    376     /// Threadsafe message logging
    377     /// </summary>
    378     private void LogMessage(string message) {
    379       lock (logLocker) {
    380         Log.LogMessage(message);
    381       }
    382     }
    383 
    384     /// <summary>
    385     /// Threadsafe exception logging
    386     /// </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     //}
    410340  }
    411341}
Note: See TracChangeset for help on using the changeset viewer.