From aa2fcb108d0018139b59811d70d6df39b71a20ad Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Fri, 5 Jan 2024 00:12:48 +0100 Subject: [PATCH] NEW/REWORKED JKQTBasePlottercan be used is re-entrant, i.e. different instances can be used from different threads in parallel (although there is significant overhead due to shared caches between the threads!). NEW added multithreaded example to demonstrate using JKQTBasePlotter in several parallel threads --- doc/CMakeLists.txt | 5 +- doc/dox/examples_and_tutorials.dox | 11 +- doc/dox/jkqtplotter_usage.dox | 6 +- doc/dox/whatsnew.dox | 2 + examples/CMakeLists.txt | 1 + examples/multithreaded/CMakeLists.txt | 33 ++++ examples/multithreaded/README.md | 110 +++++++++++++ examples/multithreaded/multithreaded.cpp | 152 ++++++++++++++++++ examples/multithreaded/multithreaded_thread.h | 73 +++++++++ screenshots/multithreaded.png | Bin 0 -> 153797 bytes screenshots/multithreaded_small.png | Bin 0 -> 37665 bytes 11 files changed, 389 insertions(+), 4 deletions(-) create mode 100644 examples/multithreaded/CMakeLists.txt create mode 100644 examples/multithreaded/README.md create mode 100644 examples/multithreaded/multithreaded.cpp create mode 100644 examples/multithreaded/multithreaded_thread.h create mode 100644 screenshots/multithreaded.png create mode 100644 screenshots/multithreaded_small.png diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index adca7470da..e210b14353 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -238,6 +238,7 @@ if(JKQtPlotter_BUILD_EXAMPLES) datastore_regression/datastore_regression,datastore_regression_lin,datastore_regression_linrobust,datastore_regression_linrobust_p,datastore_regression_linweight,datastore_regression_nonlinreg_exp,datastore_regression_nonlinreg_pow,datastore_regression_polynom,datastore_regression_polynom_errros/--iteratefunctorsteps datastore_statistics/datastore_statistics,datastore_statistics_dataonly,datastore_statistics_boxplots_simple,datastore_statistics_boxplots_outliers,datastore_statistics_hist,datastore_statistics_kde,datastore_statistics_cumhistkde/--iteratefunctorsteps datastore_statistics_2d/datastore_statistics_2d + multithreaded/multithreaded/--mdfile=${CMAKE_CURRENT_LIST_DIR}/../examples/multithreaded/README.md ) @@ -279,7 +280,7 @@ if(JKQtPlotter_BUILD_EXAMPLES) foreach(ex ${JKQTPlotter_GenerateDocScreenshots_From}) set(example ${ex}) set(basename ${ex}) - string(REGEX MATCH "(.+)/(.+)" dummy ${ex}) + string(REGEX MATCH "([^/]+)/([^/]+)" dummy ${ex}) set(extra_command "") if(CMAKE_MATCH_1 STREQUAL "" OR CMAKE_MATCH_2 STREQUAL "") set(example ${ex}) @@ -288,7 +289,7 @@ if(JKQtPlotter_BUILD_EXAMPLES) set(example ${CMAKE_MATCH_1}) set(basename ${CMAKE_MATCH_2}) set(CMAKE_MATCH_3 "") - string(REGEX MATCH "(.+)/(.*)/(.+)" dummy ${ex}) + string(REGEX MATCH "([^/]+)/([^/]*)/(.+)" dummy ${ex}) if(NOT (CMAKE_MATCH_3 STREQUAL "")) set(example ${CMAKE_MATCH_1}) set(basename ${CMAKE_MATCH_2}) diff --git a/doc/dox/examples_and_tutorials.dox b/doc/dox/examples_and_tutorials.dox index 65df90c5b2..094f8b7459 100644 --- a/doc/dox/examples_and_tutorials.dox +++ b/doc/dox/examples_and_tutorials.dox @@ -127,7 +127,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int `JKQTPXYLineGraph` and `JKQTPFilledVerticalRangeGraph`
C++ vector of data
date/time axes
plot min/max range graph
internal LaTeX parser
data from CSV files \image html second_axis_small.png \subpage JKQTPlotterSecondaryAxes - plottig with secondary axes, `JKQTPBasePlotter::addSecondaryXAxis()`/`JKQTPBasePlotter::addSecondaryYAxis()` + plottig with secondary axes, `JKQTBasePlotter::addSecondaryXAxis()`/`JKQTBasePlotter::addSecondaryYAxis()` \image html advancedlineandfillstyling_small.png \subpage JKQTPlotterAdvancedLineAndFillStyling `JKQTPXYLineGraph`, `JKQTPSpecialLineHorizontalGraph` and `JKQTPBarVerticalGraph`
C++ vector of data
advanced line styling and filling @@ -252,6 +252,15 @@ All test-projects are Qt-projects that use qmake to build. You can load them int Allows to zoom into the Mandelbrot Set, using the different Zooming methods of JKQTPlotter +\subsection jkqtp_extut_specialusecasesexamples Examples for special Use-Cases + + +
Screenshot Description Notes +
\image html multithreaded_small.png + \subpage JKQTPlotterMultiThreaded + multi-threaded plotting using JKQTBasePlotter +
+ \subsection jkqtp_extut_cmake_build Examples for CMake Build System diff --git a/doc/dox/jkqtplotter_usage.dox b/doc/dox/jkqtplotter_usage.dox index 2a72265999..27f05a6fcc 100644 --- a/doc/dox/jkqtplotter_usage.dox +++ b/doc/dox/jkqtplotter_usage.dox @@ -47,7 +47,11 @@ With simlar code you can also integrate JKQTBasePlotter into your own widgets. - + This class is immpleented in a such a way that ^different instances can be used in different parallel threads, i.e. the class is re-entrant. + There are however access to different cached data is synchronized between all threads (i.e. static internal caches are used), which limmits + the acheavable parallelization speedup! + + \see See \ref JKQTPlotterMultiThreaded for an example of multi-threaded plotting! diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index 4212ac00a7..5142fbf3e6 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -47,6 +47,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
  • FIXED issue #99: Clipping of Tick Labels: for horizontal axes, additional space at the left and/or right of the plot is allowed so labels are no longer clipped (thanks to user:allenbarnett5/a> for reporting)
  • FIXED issue #99: Height of one-column key/legend was too large (thanks to user:allenbarnett5/a> for reporting)
  • FIXED issue mentioned in #110: Lock the panning action to certain values: View zooms in, when panning close to AbosluteXY (thanks to user:sim186 for reporting)
  • +
  • FIXED: jkqtpstatSum() and jkqtpstatSumSqr() did not work, as a non-existing function is called internally
  • FIXED/IMPROVED issue #100: Add option to disable resize delay feature by setting the delay to zero (thanks to user:fpalazzolo for reporting)
  • FIXED/NEW: placement of plot-title (was not centerd in its box, but glued to the bottom) by adding a plotstyle parameter JKQTBasePlotterStyle::plotLabelOffset
  • FIXED/REWORKED issue #111: Can't write to PDF files with JKQTPlotter::saveImage() when passing a filename ending in ".pdf" (thanks to user:fpalazzolo/a> for reporting):
    While fixing this issue, the functions JKQTBasePlotter::saveImage() etc. gained a bool return value to indicate whether sacing was successful.
  • @@ -108,6 +109,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
  • NEW: added JKQTBasePlotterStyle::plotLabelTopBorder to set the spacing between top and plot label
  • NEW: Due to addition of JKQTMathText::setFontOptions() and the matchign extension of JKQTMathText::setFontSpecial() (see below) you can now add modifiers like +BOLD+ITALIC to any font-name provided to JKQTPlotter and in style INI-files
  • NEW: added JKQTPLabelMinBesides and JKQTPLabelMaxBesides to JKQTPLabelPosition, so labels can be set besides the axes
  • +
  • NEW/REWORKED JKQTBasePlottercan be used is re-entrant, i.e. different instances can be used from different threads in parallel (although there is significant overhead due to shared caches between the threads!). This is demonstrated and discussed in \ref JKQTPlotterMultiThreaded .
  • JKQTMathText: