Concurrent cartesian product algorithm in Clojure

Posted by jqno on Stack Overflow See other posts from Stack Overflow or by jqno
Published on 2010-04-02T22:40:29Z Indexed on 2010/04/02 22:43 UTC
Read the original article Hit count: 515

Is there a good algorithm to calculate the cartesian product of three seqs concurrently in Clojure?

I'm working on a small hobby project in Clojure, mainly as a means to learn the language, and its concurrency features. In my project, I need to calculate the cartesian product of three seqs (and do something with the results).

I found the cartesian-product function in clojure.contrib.combinatorics, which works pretty well. However, the calculation of the cartesian product turns out to be the bottleneck of the program. Therefore, I'd like to perform the calculation concurrently.

Now, for the map function, there's a convenient pmap alternative that magically makes the thing concurrent. Which is cool :). Unfortunately, such a thing doesn't exist for cartesian-product. I've looked at the source code, but I can't find an easy way to make it concurrent myself.

Also, I've tried to implement an algorithm myself using map, but I guess my algorithmic skills aren't what they used to be. I managed to come up with something ugly for two seqs, but three was definitely a bridge too far.

So, does anyone know of an algorithm that's already concurrent, or one that I can parallelize myself?

© Stack Overflow or respective owner

Related posts about clojure

Related posts about cartesian-product