Ejemplo n.º 1
0
 public void AssignTask(ActiveEstimatedTask task)
 {
     if (task.State == TaskState.LAUNCHED && DestinedTasks.Any())
     {
         var currentTask = LaunchedTask;
         if (currentTask != null)
         {
             DestinedTasks.Remove(currentTask);
         }
     }
     DestinedTasks.Add(task);
 }
Ejemplo n.º 2
0
        public static List <IEnumerable <ActiveEstimatedTask> > MakeOverallEstimations(EstimatedWorkflow workflow, NodeAvailabilityTime[] wrappers)
        {
            var estimatedTasks = new List <IEnumerable <ActiveEstimatedTask> >(workflow.Tasks.Count);

            for (var i = 0; i < workflow.Tasks.Count; i++)
            {
                var task = workflow.Tasks[i];
                estimatedTasks.Add(new List <ActiveEstimatedTask>());
                for (var j = 0; j < task.Estimations.Length; j++)
                {
                    var estimation    = task.Estimations[j];
                    var nodesNumber   = Int32.Parse(estimation.Result.Parameters.Single(p => p.Name == NodesCountExtractor.NODES).NewValue);
                    var coresNumber   = Int32.Parse(estimation.Result.Parameters.Single(p => p.Name == ProcessorCountPerNode.P).NewValue);
                    var nodeWrappers  = wrappers.Where(w => w.ResourceName == estimation.Resource.Name && w.Node.CoresTotal >= coresNumber && estimation.Resource.Nodes.Any(n => n.DNSName == w.NodeName));
                    var optionsNumber = (int)Math.Pow(nodeWrappers.Count(), nodesNumber);
                    var dests         = new LaunchDestination[optionsNumber];
                    var indices       = Enumerable.Repeat(0, nodesNumber).ToArray();
                    var baseValues    = Enumerable.Repeat(nodeWrappers.Count(), nodesNumber).ToArray();
                    var usedNodes     = new NodeAvailabilityTime[nodesNumber];
                    var resName       = estimation.Resource.Name;
                    for (var k = 0; k < optionsNumber; k++)
                    {
                        for (var l = 0; l < usedNodes.Length; l++)
                        {
                            usedNodes[l] = nodeWrappers.ElementAt(indices[l]);
                        }
                        var dest = new LaunchDestination()
                        {
                            ResourceName = resName,
                            NodeNames    = usedNodes.Select(un => un.NodeName).ToArray()
                        };
                        dests[k] = dest;
                        AdvanceIndices(indices, baseValues);
                    }
                    dests = dests.Where(d => d.NodeNames.Distinct().Count() == nodesNumber).ToArray();
                    foreach (var dest in dests)
                    {
                        var taskOnResource = new ActiveEstimatedTask(task);
                        taskOnResource.Estimation.Result       = estimation.Result;
                        taskOnResource.Estimation.Destination  = dest;
                        taskOnResource.Estimation.NodesTimings = nodeWrappers.Where(w => w.ResourceName == dest.ResourceName && dest.NodeNames.Contains(w.NodeName)).ToArray();
                        ((List <ActiveEstimatedTask>)estimatedTasks[i]).Add(taskOnResource);
                    }
                }
            }
            return(estimatedTasks);
        }
Ejemplo n.º 3
0
        public Estimated.LaunchPlan RescheduleEstimated(EstimatedWorkflow workflow)
        {
            Estimated.LaunchPlan mostTrueResult;
            if (!workflow.IsUrgent)
            {
                var h = CreateTaskBasedHeuristics(GetDefaultHName());
                workflow.UpdateDependencies();
                var wrappers    = GenerateWrappers(workflow);
                var estimations = MakeOverallEstimations(workflow, wrappers);
                var result      = new Estimated.LaunchPlan();
                var roots       = workflow.Tasks.Where(t => !t.IsScheduled && t.IsReady);

                {
                    var busyWrappers = wrappers.Where(w => w.GetAvailabilityTime() > E).ToArray();
                    var freeWrappers = wrappers.Except(busyWrappers).ToArray();
                    for (var i = 0; i < estimations.Count; i++)
                    {
                        if (estimations[i].Count() > 1)
                        {
                            /*var estimationsOnFreeNodes = estimations[i].Where(e => e.Estimation.Destination.NodeNames.All(n => freeWrappers.Any(fw => fw.ResourceName == e.Estimation.Destination.ResourceName && fw.NodeName == n))).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * var otherEstimations = estimations[i].Except(estimationsOnFreeNodes).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * estimations[i] = new List<ActiveEstimatedTask>();
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(estimationsOnFreeNodes);
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(otherEstimations);*/
                            estimations[i] = estimations[i].OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time).ToList();
                        }
                    }
                }

                while (roots.Count() > 0)
                {
                    var rootIds = roots.Select(r => r.Id);
                    var effectiveEstimations = estimations.Where(e => rootIds.Contains(e.First().Id)).ToList();
                    var prevInstance         = h.ChooseTask(workflow, effectiveEstimations);
                    //var nodeWrappers = wrappers.Where(w => w.ResourceName == prevInstance.Estimation.Destination.ResourceName && prevInstance.Estimation.Destination.NodeNames.Contains(w.NodeName));
                    var task            = workflow.Tasks.Single(t => t.Id == prevInstance.Id);
                    var depsWaitingTime = task.RequiresDependencies.Count == 0 ? 0 : task.RequiresDependencies.Max(d => d.ScheduledInstance.Estimation.LaunchTime + d.ScheduledInstance.Estimation.Result.Time);
                    prevInstance.Estimation.LaunchTime = Math.Max(depsWaitingTime, prevInstance.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()));
                    prevInstance.State = prevInstance.Estimation.LaunchTime > E || prevInstance.Estimation.NodesTimings.Any(w => w.GetAvailabilityTime() > E) ? TaskState.SCHEDULED : TaskState.LAUNCHED;
                    var clonedInstance = new ActiveEstimatedTask(prevInstance);

                    foreach (var node in prevInstance.Estimation.NodesTimings)
                    {
                        node.AssignTask(clonedInstance);
                    }
                    var seq = estimations.Single(e => e.First().Id == prevInstance.Id);
                    estimations.Remove(seq);
                    result.Plan.Add(clonedInstance);
                    task.ScheduledInstance = clonedInstance;
                    roots = workflow.Tasks.Where(t => !t.IsScheduled && t.IsReady);
                    var busyWrappers = wrappers.Where(w => w.GetAvailabilityTime() > E);
                    var freeWrappers = wrappers.Except(busyWrappers);
                    for (var i = 0; i < estimations.Count; i++)
                    {
                        if (estimations[i].Count() > 1)
                        {
                            /*var estimationsOnFreeNodes = estimations[i].Where(e => e.Estimation.Destination.NodeNames.All(n => freeWrappers.Any(fw => fw.ResourceName == e.Estimation.Destination.ResourceName && fw.NodeName == n))).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * var otherEstimations = estimations[i].Except(estimationsOnFreeNodes).OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time);
                             * estimations[i] = new List<ActiveEstimatedTask>();
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(estimationsOnFreeNodes);
                             * ((List<ActiveEstimatedTask>)estimations[i]).AddRange(otherEstimations);*/
                            estimations[i] = estimations[i].OrderBy(t => t.Estimation.NodesTimings.Max(n => n.GetAvailabilityTime()) + t.Estimation.Result.Time).ToList();
                        }
                    }
                }
                result.NodesTimings           = wrappers.ToList();
                result.EstimatedExecutionTime = result.Plan.Any() ? result.Plan.Max(t => t.Estimation.LaunchTime + t.Estimation.Result.Time) : 0;
                Debug.Assert(workflow.Tasks.All(t => t.IsScheduled));
                mostTrueResult = result;
            }
            else
            {
                var uwf = (EstimatedUrgentWorkflow)workflow;
                var h   = CreateUrgentHeuristics(GetDefaultUHName());
                mostTrueResult = h.MakePlan(uwf);
            }
            var hasPlanDups = mostTrueResult.Plan.Any(t => t.State == TaskState.LAUNCHED && mostTrueResult.Plan.Any(t2 => t2.Id != t.Id && t2.State == TaskState.LAUNCHED && t.Estimation.Destination.IsLike(t2.Estimation.Destination)));
            var hasWfDups   = mostTrueResult.Plan.Any(t => t.State == TaskState.LAUNCHED && workflow.ActiveTasks.Any(t2 => t.Id != t2.Id && t2.State == TaskState.LAUNCHED && t.Estimation.Destination.IsLike(t2.Estimation.Destination)));

            return((Scheduler.Estimated.LaunchPlan)mostTrueResult);
        }