oscoin / osrank-rs

A pre-alpha osrank implementation in Rust.
http://oscoin.io/
3 stars 3 forks source link

Have a go at parallelising the osrank naive algorithm #72

Closed adinapoli-mndc closed 5 years ago

adinapoli-mndc commented 5 years ago

Fixed #71. There were a bunch of modifications I had to do in order to parallelise this:

  1. Now we need to clone the RNG before passing it to each separate "thread" (it's not really a thread as we are using rayon under the hood so a thread pool is (re)used); this means that now the choice of which RNG we use is essential for the algorithm to behave correctly. More specifically, we are now dropping the use of XorShiftRng due a cloning pitfall and we are using the Xoshiro256StarStar which is of higher quality and actually faster (7 Gb/s according to the "Rust rand book" vs 5 Gb/s);

  2. After profiling the code, I did realise we had another bottleneck (that @MeBrei warned me about for a while): our RandomWalks::count_visits was eating the majority of the time for rank_network, but luckily it was easily parallelisable;

Results

Before parallelising the code, this is the result of running the osrank-export-to-gephi program:

Screenshot 2019-09-18 at 12 30 51

You will see how the full run takes 258 seconds single threaded (you see how the system % says 98, i.e. this is not using all the cores). Afterwards:

Screenshot 2019-09-18 at 13 19 40

Note that despite it seems this is slower, that's just time being confusing here: this is now using 332% of CPU time (basically almost all my 4 cores) and if you compare the log timing you will see in the sequential case the time taken was ~5mins, whereas the parallel counterpart takes roughly 2.

Important note: It has to be noted that now the algorithm is optimised for large data structures, and for small graphs we are going to pay the price for initialising the rayon thread pool and possibly this could even make things slower, for smaller inputs.

@MeBrei It might be interesting to merge this piece of work and re-generate your nice criterion graphs, to see how the system is doing now.