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 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 c in n) { Stage.AddCandidate(c); } Console.Write(n.Count() + ", "); AssignedToThisStage.Add(n); } } Console.WriteLine("total: " + Stage.Count()); foreach (var n in AssignedToThisStage) { done[n] = Stage; } } return(new StagedHoudiniPlan(Dependences)); }