blenderskool / pigmnts

🎨 Color palette generator from an image using WebAssesmbly and Rust
https://pigmnts.web.app
MIT License
73 stars 4 forks source link

Data parallelism with threads 🧵 #29

Closed blenderskool closed 3 years ago

blenderskool commented 3 years ago

Data parallelism with threads :thread:

Pigmnts now uses threads to achieve data parallelism in the assignment step of the K-means++ algorithm. The implementation follows the concept of MapReduce and makes use of crossbeam crate for scoped threads. The number of threads is set to a constant value of 5 in the library.

Coming to the interesting part of this change, threads have made pigmnts 1.5x - 2.5x faster than previous versions! :tada: The data from the tests can be found here https://docs.google.com/spreadsheets/d/1SJWTBTX9OjOPI9zdSc1T-hGUIiIv9osia1WB936vp8k/edit

Conclusions from the tests

WebAssembly?

Getting threads to get working with WebAssembly as of now is a little challenging and this experiment was majorly to test whether threads would enhance the performance in any way. Over time, these changes would be brought over to the WebAssembly library too but for now, the WebAssembly version continues to work on a single thread.

K-means and K-means++ have a lot of synchronous steps involved and parallelizing it are not very straightforward. Data parallelism here does show an improvement in the performance of the algorithm in general.

Pigmnts Library 0.7.0 :racing_car:

Pigmnts CLI 0.1.3 :racing_car: