# Parallelizing an associative binary operation

I have an associative binary operation '.', which I often use in this sort of way:

result = expr1 . expr2 . expr3 . expr4


The '.' operation is very fast, but the individual subexpressions are often hard to compute. So I would like my '.' operation to automatically parallelize itself, evaluating each of the separate subexpressions in separate kernels before finally taking the results and actually performing the operation.

How can I achieve this in Mathematica? It seems there are several challenges. One is to prevent the subexpressions evaluating before the '.' operation is evaluated.

-
Why don't you evaluate the subexpression in parallel first, and perform the . only afterwards? I don't understand why you need to couple these two things. Fold[myDot, dotIdentity, Parallelize[{expr1, expr2, expr3, expr4}]] –  Szabolcs Oct 16 '13 at 18:02
Because I use this everywhere. Having to separately parallelize everything would be a real pain. –  Jamie Vicary Oct 16 '13 at 18:04
I think Parallelize should be able to handle this properly if your . has attribute Flat, but I'm not 100% sure. Otherwise try ParallelCombine[Identity, Unevaluated[expr1.expr2.expr3.expr4]]. Search for "associative operations" here. –  Szabolcs Oct 16 '13 at 18:14