Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.