ocaml-multicore / domainslib

Parallel Programming over Domains
ISC License
172 stars 30 forks source link

Why should the binary operator for parallel_for_reduce/scan be commutative? #79

Closed favonia closed 2 years ago

favonia commented 2 years ago

Parallel reduction should work for any non-commutative binary operator as long as it is associative. A typical example is matrix multiplication, which is associative but not commutative. A naive reading of the code gave me the impression that the library will work for n-ary matrix multiplication (or any semigroup). I wonder why the documentation says the operator must be commutative? And if it is true the current code only works for commutative operators, could we improve the code so that both parallel_for_reduce and parallel_scan can work with non-commutative ones? This will make these functions much more useful.