Hello, could you tell me how you can implement working with the same Splay tree on different streams?
The tree itself is here ( code 200 lines of the classic tree, because I added a link to pastbin )
The problem is that I do not understand:
1) what flush does here (in the synch method).
comment in code:
/* * This function will be called as a "flush", with an intention * to remove inter-thread inconsistencies. */
2) I cannot imagine how to simultaneously insert and search for elements in the same Splay tree in parallel in different streams, it also always pulls the nodes into the root. Moreover, it is important that the parallel Splay tree works faster than the classic ...
UPD:
I clarified the limitations of the task. The project has main.cpp :
#include "splayset.hpp" #include "stopwatch.hpp" #include "rc4prng.hpp" #include <iostream> #include <cstdint> #include <thread> const size_t concurrency = 4, item_count = 200000, group_size = 100, group_accesses = 2000, group_count = 1000; const char rand_seed[] = "test ukolu"; void test_group (rc4prng<>& rng, splayset<uint64_t>&st) { uint64_t begin = rng.random(), mult = rng.random(); for (size_t i = 0; i < group_accesses; ++i) st.find (begin + mult * rng.random (group_size)); } int main() { splayset<uint64_t> st; rc4prng<> thread_rng[concurrency]; for (size_t tid = 0; tid < concurrency; ++tid) thread_rng[tid].load_key (rand_seed, rand_seed + 10 - tid); // :] std::thread thread[concurrency]; bpp::Stopwatch stopwatch (true); for (size_t tid = 0; tid < concurrency; ++tid) thread[tid] = std::thread ([tid, &thread_rng, &st]() { for (size_t i = 0; i < item_count; ++i) st.insert (thread_rng[tid].random()); }); for (size_t tid = 0; tid < concurrency; ++tid) thread[tid].join(); stopwatch.stop(); std::cout << stopwatch.getMiliseconds() << std::endl; stopwatch.start(); for (size_t tid = 0; tid < concurrency; ++tid) thread[tid] = std::thread ([tid, &thread_rng, &st]() { for (size_t grp = 0; grp < group_count; ++grp) test_group (thread_rng[tid], st); }); for (size_t tid = 0; tid < concurrency; ++tid) thread[tid].join(); stopwatch.stop(); std::cout << stopwatch.getMiliseconds() << std::endl; return 0; } I can only change the code of the tree itself (not main.cpp ), and therefore I do not have the opportunity to make a worker who will deal with the dispatch of threads externally.
I liked the @avp advice using scheduler , but I don’t know how to implement it, with the possibility of modifying only my splayset.hpp .
If you take into account my addition, is it possible to somehow solve this task at least partially effectively?
I very much hope for advice, for I am at a dead end.
Thank you in advance.