Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/12 22:01:38 (13 years ago)
Author:
ascheibe
Message:

#1744 added an option so that the parent task can also wait on the slave for the child tasks to finish

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveHiveEngine/HeuristicLab.HiveEngine/3.3/HiveEngine.cs

    r7320 r7417  
    4747
    4848    [Storable]
     49    public bool PauseWhileCalculatingChilds { get; set; }
     50
     51    [Storable]
    4952    private IOperator currentOperator;
    5053
     
    131134      username = cl.ClientCredentials.UserName.UserName;
    132135      password = cl.ClientCredentials.UserName.Password;
     136      PauseWhileCalculatingChilds = true;
    133137    }
    134138
     
    157161      this.nrOfSentRuns = original.nrOfSentRuns;
    158162      this.ParentTaskId = original.ParentTaskId;
     163      this.PauseWhileCalculatingChilds = original.PauseWhileCalculatingChilds;
    159164      // do not clone jobs - otherwise they would be sent with every task
    160165    }
     
    200205        cancellationToken.ThrowIfCancellationRequested();
    201206
    202         if (continueCollection != null && lastJobGuid != Guid.Empty) {
     207        if (continueCollection != null && lastJobGuid != Guid.Empty && PauseWhileCalculatingChilds) {
    203208          EngineTask[] eTasks = RetrieveResultsFromHive(lastJobGuid);
    204209          RestoreStateFromExecutedHiveTasks(eTasks, continueCollection);
     
    224229
    225230              var experiment = CreateJob();
    226               ExecuteOnHive(experiment, tasks, parentScopeClone, new CancellationToken());
    227               continueCollection = coll;
    228               Pause();
     231              var engineTasks = ExecuteOnHive(experiment, tasks, parentScopeClone, new CancellationToken());
     232              if (PauseWhileCalculatingChilds) {
     233                continueCollection = coll;
     234                Pause();
     235              } else {
     236                RestoreStateFromExecutedHiveTasks(engineTasks, coll);
     237              }
    229238            }
    230239            catch {
     
    304313
    305314    /// <summary>
    306     /// This method blocks until all jobs are finished
    307315    /// TODO: Cancelation needs to be refined; all tasks currently stay in Semaphore.WaitOne after cancelation
    308316    /// </summary>
    309317    /// <param name="tasks"></param>
    310     private void ExecuteOnHive(RefreshableJob refreshableJob, EngineTask[] tasks, IScope parentScopeClone, CancellationToken cancellationToken) {
     318    private EngineTask[] ExecuteOnHive(RefreshableJob refreshableJob, EngineTask[] tasks, IScope parentScopeClone, CancellationToken cancellationToken) {
    311319      log.LogMessage(string.Format("Executing {0} operations on the hive.", tasks.Length));
    312320      IScope[] scopes = new Scope[tasks.Length];
     
    319327          var engineHiveTask = new EngineHiveTask(tasks[i], parentScopeClone);
    320328          engineHiveTask.Task.Priority = this.Priority;
    321           if (ParentTaskId != Guid.Empty) {
     329          if (ParentTaskId != Guid.Empty && PauseWhileCalculatingChilds) {
    322330            engineHiveTask.Task.ParentTaskId = ParentTaskId;
    323331          }
     
    325333
    326334          // shuffle random variable to avoid the same random sequence in each operation; todo: does not yet work (it cannot find the random variable)
    327           IRandom random = FindRandomParameter(tasks[i].InitialOperation as IExecutionContext);
    328           if (random != null)
    329             random.Reset(random.Next());
     335          //IRandom random = FindRandomParameter(tasks[i].InitialOperation as IExecutionContext);
     336          //if (random != null)
     337          //random.Reset(random.Next());
    330338        }
    331339        HiveClient.StartJob((e) => { log.LogException(e); }, refreshableJob, cancellationToken);
     
    338346        handle.WaitOne();
    339347        refreshableJob.Progress.Finished -= new EventHandler(Progress_Finished);
     348
     349        if (!PauseWhileCalculatingChilds) {
     350
     351          while (!refreshableJob.AllJobsFinished()) {
     352            Thread.Sleep(1000);
     353          }
     354
     355          List<HiveTask> allHiveTasks = refreshableJob.HiveTasks.ToList();
     356          allHiveTasks.ForEach(x => this.ExecutionTimeOnHive += x.Task.ExecutionTime);
     357
     358          var failedJobs = allHiveTasks.Where(x => x.Task.State != TaskState.Finished);
     359          if (failedJobs.Count() > 0) {
     360            throw new HiveEngineException("Task (" + failedJobs.First().Task.Id + ") failed: " + failedJobs.First().Task.StateLog.Last().Exception);
     361          }
     362
     363          List<EngineTask> engineTasks = new List<EngineTask>();
     364
     365          foreach (var hTask in allHiveTasks) {
     366            EngineTask ehTask = (EngineTask)hTask.ItemTask;
     367            engineTasks.Add(ehTask);
     368          }
     369
     370          jobs.Clear();
     371          DeleteHiveExperiment(refreshableJob.Id);
     372
     373          return engineTasks.ToArray();
     374        } else {
     375          return null;
     376        }
    340377      }
    341378      catch (OperationCanceledException e) {
Note: See TracChangeset for help on using the changeset viewer.