private StagedHoudiniPlan ComputeFineStages()
        {
            Graph <ScheduledStage> Dependences = new Graph <ScheduledStage>();
            var done = new Dictionary <SCC <string>, ScheduledStage>();

            List <SCC <string> > components = StagesDAG.TopologicalSort().ToList();

            components.Reverse();

            for (int i = 0; i < components.Count(); i++)
            {
                ScheduledStage Stage = new ScheduledStage(i, new HashSet <string>());
                done[components[i]] = Stage;
                foreach (var c in components[i])
                {
                    Stage.AddAnnotation(c);
                }

                foreach (var s in StagesDAG.Successors(components[i]))
                {
                    Dependences.AddEdge(Stage, done[s]);
                }
            }

            return(new StagedHoudiniPlan(Dependences));
        }
Exemplo n.º 2
0
        private void ExecuteStage(ScheduledStage s)
        {
            Task.WaitAll(tasks.Where(
                             Item => plan.GetDependences(s).Contains(Item.stage)).
                         Select(Item => Item.parallelTask).ToArray());

            if (s.Count() == 0)
            {
                // This is the trivial first stage, so don't launch Houdini;
                // give this a null outcome
                return;
            }

            List <Houdini> h = AcquireHoudiniInstance();

            if (h.Count() == 0)
            {
                h.Add(new Houdini(ProgramFromFile(tempFilename), new HoudiniSession.HoudiniStatistics(), "houdiniCexTrace_" + s.GetId() + ".txt"));
            }

            System.Diagnostics.Debug.Assert(h.Count() == 1);

            Dictionary <string, bool> mergedAssignment = null;

            List <Dictionary <string, bool> > relevantAssignments;
            IEnumerable <int> completedStages;

            lock (outcomes)
            {
                relevantAssignments =
                    outcomes.Where(Item => plan.Contains(Item.Key)).
                    Select(Item => Item.Value).
                    Select(Item => Item.assignment).ToList();
                completedStages = plan.GetDependences(s).Select(Item => Item.GetId());
            }

            if (relevantAssignments.Count() > 0)
            {
                mergedAssignment = new Dictionary <string, bool>();
                foreach (var v in relevantAssignments[0].Keys)
                {
                    mergedAssignment[v] = relevantAssignments.Select(Item => Item[v]).ToList().All(Item => Item);
                }
            }

            HoudiniOutcome outcome = h[0].PerformHoudiniInference(
                s.GetId(),
                completedStages,
                mergedAssignment);

            lock (outcomes)
            {
                outcomes[s] = outcome;
            }

            ReleaseHoudiniInstance(h);
        }
        private StagedHoudiniPlan ComputeBalancedStages()
        {
            Graph <ScheduledStage> Dependences = new Graph <ScheduledStage>();
            var done = new Dictionary <SCC <string>, ScheduledStage>();

            done[GetStartNodeOfStagesDAG()] = new ScheduledStage(0, new HashSet <string>());

            int maxStageSize = 200;

            for (int stageId = 1; done.Count() != StagesDAG.Nodes.Count(); stageId++)
            {
                int                     stageSize        = 0;
                ScheduledStage          Stage            = new ScheduledStage(stageId, new HashSet <string>());
                HashSet <SCC <string> > AddedToThisStage = new HashSet <SCC <string> >();

                foreach (var n in StagesDAG.Nodes.Where(Item => !done.ContainsKey(Item)))
                {
                    if (stageSize + n.Count() > maxStageSize)
                    {
                        continue;
                    }

                    if (StagesDAG.Successors(n).Where(Item => !done.ContainsKey(Item)).Count() == 0)
                    {
                        foreach (var c in n)
                        {
                            Stage.AddAnnotation(c);
                            stageSize++;
                        }

                        foreach (var s in StagesDAG.Successors(n))
                        {
                            Dependences.AddEdge(Stage, done[s]);
                        }

                        AddedToThisStage.Add(n);
                    }
                }

                foreach (var n in AddedToThisStage)
                {
                    done[n] = Stage;
                }

                if (stageSize == 0)
                {
                    maxStageSize *= 2;
                }
            }

            return(new StagedHoudiniPlan(Dependences));
        }
        private StagedHoudiniPlan ComputeCoarseStages()
        {
            foreach (var n in StagesDAG.Nodes)
            {
                Debug.Assert(!StagesDAG.Successors(n).Contains(n));
            }

            Graph <ScheduledStage> Dependences = new Graph <ScheduledStage>();

            var done = new Dictionary <SCC <string>, ScheduledStage>();

            done[GetStartNodeOfStagesDAG()] = new ScheduledStage(0, new HashSet <string>());

            for (int stageId = 1; done.Count() != StagesDAG.Nodes.Count(); stageId++)
            {
                var Stage = new ScheduledStage(stageId, new HashSet <string>());
                HashSet <SCC <string> > AssignedToThisStage = new HashSet <SCC <string> >();

                foreach (var n in StagesDAG.Nodes.Where(Item => !done.ContainsKey(Item)))
                {
                    if (StagesDAG.Successors(n).Where(Item => !done.ContainsKey(Item)).Count() == 0)
                    {
                        foreach (var s in StagesDAG.Successors(n))
                        {
                            Debug.Assert(s != n);
                            Debug.Assert(Stage != done[s]);
                            Dependences.AddEdge(Stage, done[s]);
                        }

                        foreach (var a in n)
                        {
                            Stage.AddAnnotation(a);
                        }

                        AssignedToThisStage.Add(n);
                    }
                }

                foreach (var n in AssignedToThisStage)
                {
                    done[n] = Stage;
                }
            }

            return(new StagedHoudiniPlan(Dependences));
        }
Exemplo n.º 5
0
 internal StagedHoudiniTask(ScheduledStage stage, Task parallelTask)
 {
     this.stage        = stage;
     this.parallelTask = parallelTask;
 }