1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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}]] $\endgroup$ – Szabolcs Oct 16 '13 at 18:02
  • $\begingroup$ Because I use this everywhere. Having to separately parallelize everything would be a real pain. $\endgroup$ – Jamie Vicary Oct 16 '13 at 18:04
  • $\begingroup$ 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. $\endgroup$ – Szabolcs Oct 16 '13 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.