With the overhead of threading, isn't the triumph of a transducer (no
seq allocations) rather subtle in the case of pmap?


At any rate!, as a point of interest, since you mentioned a quirk of
pmap's thread usage: It apparently has to do with whether the input 
sequence is a
chunked sequence or not.

Comparing two possible inputs

user> (def c (into [] (range 50))) ;; chunked

user> (def n (into '() (range 50))) ;; not chunked

With pmap invoking a function that just returns the thread's name (and
takes some time, so as to keep its assigned thread busy enough not to
accept more tasks right away)

user> (defn f [x] (Thread/sleep 22) (.getName (Thread/currentThread)))
#'user/f
user> (count (distinct (pmap f c)))
32
user> (count (distinct (pmap f n)))
7

The test is not perfect because it does not show that all 32
threads were used *at once*. There were simply 32 distinct threads used at 
one
point or another.  Nonetheless the difference between 7 and 32 is
suggestive.

In this environment there are 4 "processors", so 32 is indeed more than you 
might want.

The docstring about pmap could be clearer about this.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to