You're doing all your computation in the generation of the lazy
sequence (which is in order). Then you're mapping "identity" in
parallel, but that doesn't do anything.

If you're willing to lose the "for" style bindings, try something more
like this:

(defmacro pdoseq
  "Run over a sequence in parallel (like pmap)"
  [seq-exprs & body]
  (let [pairs (partition 2 seq-exprs)]
    `(do (doall (pmap (fn ~(vec (map first pairs)) ~@body) ~@(map
second pairs))) nil)))

On Thu, May 24, 2012 at 3:56 PM, Cedric Greevey <cgree...@gmail.com> wrote:
> For some reason, this doesn't actually seem to be executing in parallel:
>
> (defmacro pdoseq
>  "Bindings as for for, but parallel execution as per pmap, pcalls,
> pvalues; returns
>   nil."
>  [seq-exprs & body]
>  `(do
>     (doall
>       (pmap identity
>             (for ~seq-exprs (do ~@body)))
>     nil)))
>
> user=> (pdoseq [i (range 10)] (println n))
> 0
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
>
> Never any interleaving of output and if I give it a big CPU-bound job
> to do for each integer it only saturates one core.
>
> I thought it might be a chunked-seq issue, but:
>
> user=> (chunked-seq? (range 10))
> false
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to