4 releases
new 0.2.2 | Apr 11, 2025 |
---|---|
0.2.1 | Feb 5, 2025 |
0.2.0 | Feb 5, 2025 |
0.1.0 | Feb 4, 2025 |
#366 in Concurrency
371 downloads per month
20KB
64 lines
Buffered Mutexes Implementing the Reducer Parallel–Programming Pattern
Sometimes, multiple threads need to update a shared value so frequently that the
overhead of an atomic or a Mutex
becomes a bottleneck. If, however, only
the cumulative result of the update is important, and not any of the
intermediate values, a BufMutex
makes it possible to pass around multiple
cloneable SharedBufMutex
s containing a local value that can be updated
without synchronization, and that will be combined into the global value when
the SharedBufMutex
s are dropped. This pattern works particular well with
methods such as like Rayon's for_each_with
, map_with
, and so on.
Structures of this type are called reducers in OpenMP and reducer
hyperobjects in Cilk; they fuel the inner workings of Rayon. However,
Rayon does not expose them—you access them through a functional (or pull)
interface (e.g., via the fold
method). If you need an imperative (or push)
interface (e.g., direct mutation methods) you can use a BufMutex
.
Acknowledgments
This software has been partially supported by project SERICS (PE00000014) under the NRRP MUR program funded by the EU - NGEU. Views and opinions expressed are however those of the authors only and do not necessarily reflect those of the European Union or the Italian MUR. Neither the European Union nor the Italian MUR can be held responsible for them.