public static void Main() { var simulation = new SimulationControllerBase <FatTreeCluster>(generator: () => new FatTreeCluster()); simulation.SimulationStep(); var filterOut = new Type[] { typeof(NetworkChannel) }; var s = simulation.DebugGraphToDot(filterOut); Console.Write(simulation); File.WriteAllText("./fattree.dot", s); Console.ReadLine(); }
public static string DebugGraphToDot <T>(this SimulationControllerBase <T> simulation, Type[] filterOut = null) where T : Group { if (filterOut == null) { filterOut = new Type[] { } } ; var s = @"digraph G { rankdir=LR; graph[K=1. sep=31 overlap=false outputorder=edgesfirst ranksep=5 concentrate=true]; edge[arrowhead=vee, arrowtail=inv, arrowsize=.7, fontsize=10, color=darkgray]"; //Gather var gu = new UIGraph(); Action <Group> toDot = null; toDot = group => { s += "subgraph place {\n" + "node [shape=circle, style=filled, fixedsize=true, fillcolor=white, border=black, fontcolor=gray, label=\" \",height=.3,width=.3];\n"; Func <Extensions.NodeDetails, UIGraphNode> getNode = d => { var forbidden = filterOut.Any(type => d.Host.From.GetType().IsAssignableFrom(type)); if (d.IsPatternMember) { forbidden = filterOut.Any(type => d.PatternSource.GetType().IsAssignableFrom(type)); } var n = new UIGraphNode { src = d }; if (!forbidden) { n.remove = false; } else { n.remove = true; } return(n); }; foreach (var fieldDescriptor in group.Descriptor.Places.Values) { var d = fieldDescriptor.Value.DebugSource(group); var n = getNode(d); if (!n.remove) { s += d + " [xlabel = \"" + d.Name + "\"];\n"; } gu.Nodes.Add(n, new List <UIGraphNode>()); } s += "}\n"; s += "subgraph transitions {\n" + "node [shape=rect,height=.4,width=.1,label=\"\",fillcolor=black, style=filled];\n"; foreach (var fieldDescriptor in group.Descriptor.Transitions.Values) { var d = fieldDescriptor.Value.DebugSource(group); var n = getNode(d); if (!n.remove) { s += d + " [xlabel = \"" + d.Name + "\"];\n"; } gu.Nodes.Add(n, new List <UIGraphNode>()); } s += "}\n"; foreach (var fieldDescriptor in group.Descriptor.Transitions.Values) { fieldDescriptor.Value.Links.ForEach( link => { var from = link.From.DebugSource(group); var to = link.To.DebugSource(group); var ff = getNode(from); var tto = getNode(to); gu.Nodes[ff].Add(tto); } ); } group.Descriptor.ApplyToAllSubGroups(descriptor => toDot(descriptor.Value)); }; toDot(simulation.TopGroup); //Map filter var ngu = new UIGraph(); Action <UIGraphNode, UIGraphNode, List <UIGraphNode> > act = null; act = (source, current, visited) => { gu.Nodes[current].ForEach( node => { if (visited.Contains(node)) { return; } visited.Add(node); if (node.remove) { act(source, node, visited); } else { if (!ngu.Nodes.ContainsKey(source)) { ngu.Nodes.Add(source, new List <UIGraphNode>()); } ngu.Nodes[source].Add(node); } } ); }; foreach (var kn in gu.Nodes.Keys.Where((node, i) => !node.remove)) { act(kn, kn, new List <UIGraphNode>()); } //Reduce var ngu2 = new UIGraph(); foreach (var kvp in ngu.Nodes) { ngu2.Nodes.Add(kvp.Key, kvp.Value.Distinct().ToList()); } //Print foreach (var kvp in ngu2.Nodes) { kvp.Value.ForEach( node => { s += kvp.Key.src + " -> " + node.src + ";\n"; } ); } s += "}"; return(s); } }
public static void Main(float time = 20, int imgWidth = 600, int imgHeight = 400, string imgPath = "./") { //Model test configurations var minProcessors = 1; var maxProcessors = 121; var seialFraction = new List <Fraction> { Fraction.FromDoubleRounded(0.1), Fraction.FromDoubleRounded(0.2), Fraction.FromDoubleRounded(0.3), Fraction.FromDoubleRounded(0.4), Fraction.FromDoubleRounded(0.5), Fraction.FromDoubleRounded(0.6), Fraction.FromDoubleRounded(0.7), Fraction.FromDoubleRounded(0.8), Fraction.FromDoubleRounded(0.9) }; //Running models var plotData = seialFraction.ToDictionary(fraction => fraction, fraction => new List <PlotFrame>()); seialFraction.ForEach( parallelPart => { for (Fraction i = minProcessors; i < maxProcessors;) { var processors = i.ToInt32(); var simulation = new SimulationControllerBase <GustafsonLaw>( generator: () => new GustafsonLaw(time, processors, parallelPart), strategy: SimulationStrategy.None ); var stop = false; simulation.OnPlaceUpdate( simulation.state.TopGroup.Done, list => { stop = true; } ); while (!stop) { simulation.SimulationStep(); } //Logging results Console.WriteLine( $"preformed tasks: {simulation.TopGroup.DoneTasks.GetMarks().Count} on processors: {processors} steps: {((simulation.state.CurrentTime - simulation.TopGroup.DoneChecker.TimeScale) / simulation.state.TimeStep).ToDouble()} time: {simulation.state.CurrentTime.ToDouble()} timeStep {simulation.state.TimeStep}" ); plotData[parallelPart].Add( new PlotFrame(processors, simulation.TopGroup.DoneTasks.GetMarks().Count) ); i += 10; if (i % 10 != 0) { i -= 1; } } } ); //Plotting var i = 0; var xPositions = plotData.Values.First().Select(frame => Convert.ToDouble(++i)).ToArray(); var xLabels = plotData.Values.First().Select(frame => frame.Key.ToString()).ToArray(); var plt2 = new Plot(imgWidth, imgHeight); foreach (var kvp in plotData) { var ys = kvp.Value.Select(frame => frame.Value / kvp.Value[0].Value).ToArray(); var esi = new NaturalSpline(xPositions, ys, 15); plt2.PlotScatter(esi.interpolatedXs, esi.interpolatedYs, markerSize: 0, label: null); plt2.PlotScatter(xPositions, ys, label: kvp.Key.ToString(), markerSize: 5, lineWidth: 0); } plt2.PlotHLine(1, lineStyle: LineStyle.Dash); plt2.Legend(); plt2.XTicks(xPositions, xLabels); plt2.Title("Gustafson's law"); plt2.YLabel("SpeedUp"); plt2.XLabel("Number of processors"); plt2.SaveFig(imgPath + "GustafsonSpeedUp.png"); }