/** Print a table of metrics for the given data. */ private static void printData(Data data) { System.out.println("n\tK\tT\tSpdup\tEffic\tEDSF"); System.out.println( data.n + "\t" + FMT_0.format(data.K_series.x(0)) + "\t" + FMT_0.format(data.T_series.x(0)) + "\t" + FMT_3.format(data.Speedup_series.x(0)) + "\t" + FMT_3.format(data.Eff_series.x(0))); for (int i = 1; i < data.K_series.length(); ++i) { System.out.println( data.n + "\t" + FMT_0.format(data.K_series.x(i)) + "\t" + FMT_0.format(data.T_series.x(i)) + "\t" + FMT_3.format(data.Speedup_series.x(i)) + "\t" + FMT_3.format(data.Eff_series.x(i)) + "\t" + FMT_3.format(data.EDSF_series_2.x(i - 1))); } }
/** Plot the given data. */ private static void plotData(Data data, String label) { int len = data.K_series.length(); T_plot.xySeries(new AggregateXYSeries(data.K_series, data.T_series)) .label(label, data.K_series.x(len - 1), data.T_series.x(len - 1)); Speedup_plot.xySeries(new AggregateXYSeries(data.K_series, data.Speedup_series)) .label(label, data.K_series.x(len - 1), data.Speedup_series.x(len - 1)); Eff_plot.xySeries(new AggregateXYSeries(data.K_series, data.Eff_series)) .label(label, data.K_series.x(len - 1), data.Eff_series.x(len - 1)); EDSF_plot.xySeries(new AggregateXYSeries(data.K_series_2, data.EDSF_series_2)) .label(label, data.K_series_2.x(len - 2), data.EDSF_series_2.x(len - 2)); }
/** Parse the given line of input. */ private static void parseLine(String line, int linenum) { Scanner scanner = new Scanner(line); if (scanner.hasNextInt()) { // A running time data line. Parse contents. int n = scanner.nextInt(); if (!scanner.hasNextInt()) error("K invalid", linenum); int K = scanner.nextInt(); if (K < 0) error("K < 0", linenum); if (K == 0) return; // Ignore T_seq K_max = Math.max(K_max, K); double T_min = Double.POSITIVE_INFINITY; double T_max = Double.NEGATIVE_INFINITY; while (scanner.hasNextLong()) { double T = (double) scanner.nextLong(); if (T <= 0.0) error("T invalid", linenum); T_min = Math.min(T_min, T); T_max = Math.max(T_max, T); } if (T_min == Double.POSITIVE_INFINITY) { error("T values missing", linenum); } // Record data. Data data = getData(n); if (K == 0) { data.T_seq = T_min; data.T_max_seq = T_max; data.Dev_seq = (T_max - T_min) / T_min; } else if (K == 1) { double Speedup = data.T_seq == 0.0 ? 1.0 : data.T_seq / T_min; double Eff = Speedup; double Dev = (T_max - T_min) / T_min; data.T_par_1 = T_min; data.K_series.add(K); data.T_series.add(T_min); data.T_max_series.add(T_max); data.Speedup_series.add(Speedup); data.Eff_series.add(Eff); data.Dev_series.add(Dev); } else { double Speedup = data.T_seq == 0.0 ? data.T_par_1 / T_min : data.T_seq / T_min; double Eff = Speedup / K; double Dev = (T_max - T_min) / T_min; double EDSF = (K * T_min - data.T_par_1) / data.T_par_1 / (K - 1); data.K_series.add(K); data.T_series.add(T_min); data.T_max_series.add(T_max); data.Speedup_series.add(Speedup); data.Eff_series.add(Eff); data.Dev_series.add(Dev); data.K_series_2.add(K); data.EDSF_series_2.add(EDSF); } } else { // A problem size specification line or plot specification line. String keyword = scanner.next(); if (keyword.equals("n")) { // A problem size specification line. Parse contents. if (!scanner.hasNextInt()) error("Missing n value", linenum); int n = scanner.nextInt(); if (!scanner.hasNextDouble()) error("Missing N value", linenum); double N = scanner.nextDouble(); String labelText = scanner.findInLine(QUOTED_STRING_PATTERN); if (labelText == null) error("Missing quoted label text", linenum); labelText = labelText.substring(1, labelText.length() - 1); // Record contents. Data data = getData(n); data.N = N; data.labelText = labelText; } else if (keyword.equals("time")) { parsePlotSpecification(T_plot, scanner, linenum); } else if (keyword.equals("speedup")) { parsePlotSpecification(Speedup_plot, scanner, linenum); } else if (keyword.equals("eff")) { parsePlotSpecification(Eff_plot, scanner, linenum); } else if (keyword.equals("edsf")) { parsePlotSpecification(EDSF_plot, scanner, linenum); } else { error("Unknown command", linenum); } } }