public void TestUpdateReadyOperationsMultiDependecy() { TestBlock operation1 = new TestBlock(new List <FluidBlock> { }, "op1", new TestModule()); TestBlock operation3 = new TestBlock(new List <FluidBlock> { }, "op3", new TestModule()); TestBlock operation2 = new TestBlock(new List <FluidBlock> { operation1, operation3 }, "op2", new TestModule()); TestBlock operation4 = new TestBlock(new List <FluidBlock> { }, "op4", new TestModule()); DFG <Block> dfg = new DFG <Block>(); dfg.AddNode(operation1); dfg.AddNode(operation3); dfg.AddNode(operation2); dfg.AddNode(operation4); dfg.FinishDFG(); //Now the operations associated with node 1, //should wait for the operation assocaited with node 0 and 2. Assay assay = new Assay(dfg); //Remove first dependecy assay.UpdateReadyOperations(dfg.Nodes[2].value); Assert.AreEqual(assay.GetReadyOperations().Count, dfg.Nodes.Count - 2); Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[0].value)); Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[3].value)); Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[1].value)); Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[2].value)); Assert.IsFalse(dfg.Nodes[0].value.IsDone); Assert.IsFalse(dfg.Nodes[1].value.IsDone); Assert.IsTrue(dfg.Nodes[2].value.IsDone); Assert.IsFalse(dfg.Nodes[3].value.IsDone); //remove last dependecy assay.UpdateReadyOperations(dfg.Nodes[0].value); Assert.AreEqual(assay.GetReadyOperations().Count, dfg.Nodes.Count - 2); Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[1].value)); Assert.IsTrue(assay.GetReadyOperations().Contains(dfg.Nodes[3].value)); Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[0].value)); Assert.IsFalse(assay.GetReadyOperations().Contains(dfg.Nodes[2].value)); Assert.IsTrue(dfg.Nodes[0].value.IsDone); Assert.IsFalse(dfg.Nodes[1].value.IsDone); Assert.IsTrue(dfg.Nodes[2].value.IsDone); Assert.IsFalse(dfg.Nodes[3].value.IsDone); }
public static DFG <Block> OptimizeCDFG <T>(int width, int height, CDFG graph, CancellationToken keepRunning, bool useGC) { DFG <Block> runningGraph = graph.StartDFG; Stack <IControlBlock> controlStack = new Stack <IControlBlock>(); Stack <List <string> > scopedVariables = new Stack <List <string> >(); controlStack.Push(null); scopedVariables.Push(new List <string>()); DFG <Block> bigDFG = new DFG <Block>(); Dictionary <string, string> renamer = new Dictionary <string, string>(); Dictionary <string, string> variablePostfixes = new Dictionary <string, string>(); Schedule scheduler = new Schedule(width, height); scheduler.SHOULD_DO_GARBAGE_COLLECTION = useGC; List <StaticDeclarationBlock> staticModuleDeclarations = runningGraph.Nodes.Where(node => node.value is StaticDeclarationBlock) .Select(node => node.value as StaticDeclarationBlock) .ToList(); if (staticModuleDeclarations.Count > 0) { scheduler.PlaceStaticModules(staticModuleDeclarations); scopedVariables.Peek().AddRange(scheduler.NewVariablesCreatedInThisScope.Distinct()); } int nameID = 0; while (runningGraph != null) { int time = scheduler.ListScheduling <T>(runningGraph, null); scopedVariables.Peek().AddRange(scheduler.NewVariablesCreatedInThisScope.Distinct().Where(x => !x.Contains("#@#Index"))); runningGraph.Nodes.ForEach(x => x.value.IsDone = false); Assay fisk = new Assay(runningGraph); foreach (Block toCopy in fisk) { if (toCopy is FluidBlock fluidBlockToCopy) { if (!variablePostfixes.ContainsKey(toCopy.OutputVariable)) { variablePostfixes.Add(toCopy.OutputVariable, $"##{nameID++}"); } Block copy = fluidBlockToCopy.CopyBlock(bigDFG, renamer, variablePostfixes[toCopy.OutputVariable]); bigDFG.AddNode(copy); } fisk.UpdateReadyOperations(toCopy); } runningGraph.Nodes.ForEach(x => x.value.Reset()); var dropPositionsCopy = scheduler.FluidVariableLocations.ToDictionary(); List <string> variablesOutOfScope; (runningGraph, variablesOutOfScope) = GetNextGraph(graph, runningGraph, null, scheduler.Variables, controlStack, scopedVariables, scheduler.FluidVariableLocations); if (useGC) { AddWasteBlocks(variablesOutOfScope, bigDFG, renamer, dropPositionsCopy, staticModuleDeclarations); } foreach (var item in variablesOutOfScope) { renamer.Remove(item); variablePostfixes.Remove(item); } if (keepRunning.IsCancellationRequested) { return(null); } } if (useGC) { AddWasteBlocks(scopedVariables.Pop(), bigDFG, renamer, scheduler.FluidVariableLocations, staticModuleDeclarations); } bigDFG.FinishDFG(); return(bigDFG); }