From 5dd9bc96d4b1785a0ffe35488fa5aa0ba20b58ba Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 9 Jan 2024 10:27:39 +0100 Subject: smpopenmp01: Convert to JSON data This avoids a dependency on the non-standard libxml2 module. --- testsuites/smptests/smpopenmp01/init.c | 36 ++++--- testsuites/smptests/smpopenmp01/smpopenmp01.py | 71 ++++++------ testsuites/smptests/smpopenmp01/smpopenmp01.scn | 137 +++++++++++------------- 3 files changed, 118 insertions(+), 126 deletions(-) (limited to 'testsuites/smptests') diff --git a/testsuites/smptests/smpopenmp01/init.c b/testsuites/smptests/smpopenmp01/init.c index 46577ff4b2..d37fe852cf 100644 --- a/testsuites/smptests/smpopenmp01/init.c +++ b/testsuites/smptests/smpopenmp01/init.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 embedded brains GmbH & Co. KG + * Copyright (C) 2017, 2024 embedded brains GmbH & Co. KG * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -143,21 +143,31 @@ static void do_bench(const char *name, void (*bench)(void), int n) (*bench)(); } delta = omp_get_wtime() - start; - printf("\t\t<%sBench unit=\"s\">%f\n", name, delta, name); + printf(",\n \"%s-bench\": %f", name, delta); } +static const char *test_sep = ""; + static void microbench(int num_threads, int n) { - printf("\t\n", num_threads, n); omp_set_num_threads(num_threads); - do_bench("Barrier", barrier_bench, n); - do_bench("Parallel", parallel_bench, n); - do_bench("Static", static_bench, n); - do_bench("Dynamic", dynamic_bench, n); - do_bench("Guided", guided_bench, n); - do_bench("Runtime", runtime_bench, n); - do_bench("Single", single_bench, n); - printf("\t\n"); + printf( + "%s{\n" + " \"num-threads\": %i,\n" + " \"major-loop-count\": %i", + test_sep, + num_threads, + n + ); + test_sep = ", "; + do_bench("barrier", barrier_bench, n); + do_bench("parallel", parallel_bench, n); + do_bench("static", static_bench, n); + do_bench("dynamic", dynamic_bench, n); + do_bench("guided", guided_bench, n); + do_bench("runtime", runtime_bench, n); + do_bench("single", single_bench, n); + printf("\n }"); } static int estimate_3s_runtime_with_one_proc(void) @@ -186,7 +196,7 @@ static void test(void) int num_procs; int n; - printf("\n"); + printf("*** BEGIN OF JSON DATA ***\n[\n "); n = estimate_3s_runtime_with_one_proc(); num_procs = omp_get_num_procs(); @@ -196,7 +206,7 @@ static void test(void) microbench(i, n); } - printf("\n"); + printf("\n]\n*** END OF JSON DATA ***\n"); } #ifdef __rtems__ diff --git a/testsuites/smptests/smpopenmp01/smpopenmp01.py b/testsuites/smptests/smpopenmp01/smpopenmp01.py index 8545d2d91f..227b089926 100644 --- a/testsuites/smptests/smpopenmp01/smpopenmp01.py +++ b/testsuites/smptests/smpopenmp01/smpopenmp01.py @@ -1,9 +1,6 @@ -#!/usr/bin/env python - # SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2017 embedded brains GmbH & Co. KG +# Copyright (C) 2017, 2024 embedded brains GmbH & Co. KG # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -25,37 +22,39 @@ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -# +import json import re -import libxml2 -from libxml2 import xmlNode -import matplotlib.pyplot as plt -data = open('smpopenmp01.scn').read() -data = re.sub(r'\*\*\*.*', '', data) -doc = libxml2.parseDoc(data) -ctx = doc.xpathNewContext() - -plt.title('OpenMP Microbench') -plt.xlabel('Number of Threads') -plt.ylabel('Relative Duration') - -def m(n): - return float(n.getContent()) - -def p(bench): - d = map(m, ctx.xpathEval('/SMPOpenMP01/Microbench/' + bench)) - y = [x / d[0] for x in d] - x = range(1, len(y) + 1) - plt.xticks(x) - plt.plot(x, y, label = bench, marker = 'o') - -p('BarrierBench') -p('ParallelBench') -p('StaticBench') -p('DynamicBench') -p('GuidedBench') -p('RuntimeBench') -p('SingleBench') -plt.legend(loc = 'best') -plt.show() +import matplotlib.pyplot as plt # type: ignore +from matplotlib import ticker # type: ignore + + +def _plot(data: dict) -> None: + _, axes = plt.subplots() + axes.set_title("OpenMP Microbench") + axes.set_xlabel("Number of Threads") + axes.set_ylabel("Relative Duration") + x = list(range(1, len(data) + 1)) + axes.xaxis.set_major_locator(ticker.FixedLocator(x)) + for key in [ + "barrier-bench", "dynamic-bench", "guided-bench", "parallel-bench", + "runtime-bench", "single-bench", "static-bench" + ]: + d = [results[key] for results in data] + y = [x / d[0] for x in d] + axes.plot(x, y, label=key.replace("-bench", ""), marker="o") + axes.legend(loc="best") + plt.savefig("smpopenmp01.png") + plt.savefig("smpopenmp01.pdf") + plt.close() + + +_JSON_DATA = re.compile( + r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)" + r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL) + +with open("smpopenmp01.scn", "r", encoding="utf-8") as src: + match = _JSON_DATA.search(src.read()) + data = json.loads(match.group(1)) + +_plot(data) diff --git a/testsuites/smptests/smpopenmp01/smpopenmp01.scn b/testsuites/smptests/smpopenmp01/smpopenmp01.scn index 6f63ddca1d..2d6c944d3f 100644 --- a/testsuites/smptests/smpopenmp01/smpopenmp01.scn +++ b/testsuites/smptests/smpopenmp01/smpopenmp01.scn @@ -1,81 +1,64 @@ + + SIS - SPARC/RISCV instruction simulator 2.30, copyright Jiri Gaisler 2020 + Bug-reports to jiri@gaisler.se + + GR740/LEON4 emulation enabled, 4 cpus online, delta 50 clocks + + Loaded build/sparc/gr740/testsuites/smptests/smpopenmp01.exe, entry 0x00000000 + + *** BEGIN OF TEST SMPOPENMP 1 *** -*** TEST VERSION: 5.0.0.4c8cffc19865eaa3b033ce2776bcce9992f24b18 +*** TEST VERSION: 6.0.0.43eecff0b1b2915b87d5324ae562888851cabdaf *** TEST STATE: EXPECTED_PASS -*** TEST BUILD: RTEMS_POSIX_API RTEMS_SMP -*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 6d9c77c77d271d1fc2dfe8493d6713930b52a6dd, Newlib 3.0.0) - - - 0.720318 - 1.121403 - 0.059288 - 0.440113 - 0.003230 - 0.440121 - 0.116486 - - - 0.416734 - 0.259013 - 0.015311 - 0.196751 - 0.002367 - 0.199640 - 0.077629 - - - 0.748332 - 0.387318 - 0.021244 - 0.141558 - 0.001544 - 0.142693 - 0.117683 - - - 0.552830 - 0.323241 - 0.017796 - 0.099475 - 0.001259 - 0.100053 - 0.091069 - - - 0.882791 - 0.452561 - 0.023620 - 0.094107 - 0.000989 - 0.093911 - 0.130070 - - - 0.670385 - 0.393587 - 0.021141 - 0.072322 - 0.000937 - 0.069804 - 0.104107 - - - 1.031511 - 0.466571 - 0.024944 - 0.069194 - 0.000814 - 0.069596 - 0.133137 - - - 0.761015 - 0.452577 - 0.023979 - 0.061193 - 0.000799 - 0.061519 - 0.114285 - - +*** TEST BUILD: RTEMS_SMP +*** TEST TOOLS: 13.2.0 20230727 (RTEMS 6, RSB d3d738c35a71ca05f675b188539225099401ac79, Newlib a021448) +*** BEGIN OF JSON DATA *** +[ + { + "num-threads": 1, + "major-loop-count": 1, + "barrier-bench": 0.269517, + "parallel-bench": 1.277477, + "static-bench": 0.073541, + "dynamic-bench": 0.118271, + "guided-bench": 0.008089, + "runtime-bench": 0.142307, + "single-bench": 0.034294 + }, { + "num-threads": 2, + "major-loop-count": 1, + "barrier-bench": 0.269345, + "parallel-bench": 0.557423, + "static-bench": 0.033622, + "dynamic-bench": 0.059762, + "guided-bench": 0.004065, + "runtime-bench": 0.072107, + "single-bench": 0.033129 + }, { + "num-threads": 3, + "major-loop-count": 1, + "barrier-bench": 0.271522, + "parallel-bench": 0.631576, + "static-bench": 0.036074, + "dynamic-bench": 0.039981, + "guided-bench": 0.002757, + "runtime-bench": 0.049072, + "single-bench": 0.033129 + }, { + "num-threads": 4, + "major-loop-count": 1, + "barrier-bench": 0.272048, + "parallel-bench": 0.705746, + "static-bench": 0.039061, + "dynamic-bench": 0.030069, + "guided-bench": 0.002095, + "runtime-bench": 0.037570, + "single-bench": 0.033176 + } +] +*** END OF JSON DATA *** *** END OF TEST SMPOPENMP 1 *** + +cpu 0 in error mode (tt = 0x80) + 706370700 0000cac0: 91d02000 ta 0x0 -- cgit v1.2.3