From a0336685dc0e75846ef087ed75126f51f7ec2615 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 16 Nov 2024 13:30:22 +0100 Subject: [PATCH] Library: investigate glitches when drawing concurrently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Further investigation shows that the ''data type used for computation'' plays a crucial role. The (recommended) 64bit mersenne twister uses the full value range of the working data type, which on a typical 64bit system is also `uint64_t`. In this case, values corrupted by concurrency go unnoticed. This can be **verified empirically** : the distribution of shifts from the theoretical mean value is in the expected low range < 2‰ However, when using the 32bit mersenne engine, the working data type is still uint64_t. In this case a **significant number of glitches** can be shown empricially. When drawing 1 Million values, in 80% of all runs at least one glitch and up to 5 glitches can happen, and the mean values are **significantly skewed** --- tests/library/random-concurrent-test.cpp | 38 ++++++++++++++------- wiki/thinkPad.ichthyo.mm | 42 ++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/tests/library/random-concurrent-test.cpp b/tests/library/random-concurrent-test.cpp index 2d8447799..1be684fc7 100644 --- a/tests/library/random-concurrent-test.cpp +++ b/tests/library/random-concurrent-test.cpp @@ -37,15 +37,20 @@ #include "lib/test/diagnostic-output.hpp" #include +#include +//#include //using util::isLimited; +//using std::array; +using std::tuple; +using std::deque; namespace lib { namespace test { namespace { const uint NUM_THREADS = 8; - - const uint NUM_INVOKE = 1'000'000; + const uint NUM_REPEATS = 10; + const uint NUM_INVOKES = 1'000'000; } @@ -71,36 +76,47 @@ namespace test { investigate_concurrentAccess() { struct Results - : std::deque + : deque> , Sync<> { void - post (double val) + post (double err, uint fails) { Lock sync(this); - push_back (val); + emplace_back (err, fails); } }; Results results; - const uint N = NUM_INVOKE; - auto expect = RAND_MAX / 2; + using Engine = std::mt19937; +// using Engine = std::mt19937_64; + + Engine ranGen{defaultGen.u64()}; + + const uint N = NUM_INVOKES; + auto expect = (Engine::max() - Engine::min()) / 2; auto drawRandom = [&]() { + uint fail{0}; double avg{0.0}; for (uint i=0; i Engine::max()) + ++fail; + avg += 1.0/N * (r % Engine::max()); + } auto error = avg/expect - 1; - results.post (error); + results.post (error, fail); }; - auto [dur,sum] = threadBenchmark (drawRandom, 1); + auto [dur,sum] = threadBenchmark (drawRandom, NUM_REPEATS); for (auto res : results) SHOW_EXPR(res); SHOW_EXPR(sum) - SHOW_EXPR(dur/NUM_INVOKE) + SHOW_EXPR(dur/NUM_INVOKES) } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index faee094c2..5f7490168 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -58053,14 +58053,52 @@ - + + + + + + + + + +

+ diese verwendet uint_fast32_t, das aber auf meinem System ebenfalls auf unit64_t gemapped ist +

+ + +
+ +
+
- + + + + + + + + + + + + + + + + + + + + + +