On Sun, Jan 23, 2011 at 10:31 PM, Ken Wesson <kwess...@gmail.com> wrote:
> On Sun, Jan 23, 2011 at 8:56 PM, Michael Gardner <gardne...@gmail.com> wrote:
>> Suppose I have a sequence of tasks I'd like to parallelize using pmap. The 
>> amount of CPU time these tasks require varies greatly; in particular, many 
>> of them will require virtually no work. Can I rely on pmap to divide the 
>> work efficiently even if there is some pattern to the distribution of easy 
>> tasks (e.g. clumped at the beginning, or every nth)? Assume it's not 
>> possible to identify the easy tasks beforehand.
>
> Here's a little data:
> user=> (def printer (agent nil))
> #'user/printer
> user=> (defn xyz [n] (send printer (fn [_] println
> (Thread/currentThread))) (* n n))

Eh, that's weird. That's not the definition I used. I used

(defn xyz [n] (let [t (Thread/currentThread)] (send printer (fn [_]
(println t)))) (* n n))

of course so it would be the pmap thread, not the agent thread, in the
printout. I had been experimenting with investigating the agent thread
pools too, so the defn must have come from that part of the REPL
session.

This data:

> #<Thread Thread[pool-2-thread-25,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-25,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-21,5,main]>
> #<Thread Thread[pool-2-thread-21,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-29,5,main]>
> #<Thread Thread[pool-2-thread-29,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-22,5,main]>
> #<Thread Thread[pool-2-thread-30,5,main]>
> #<Thread Thread[pool-2-thread-28,5,main]>
> #<Thread Thread[pool-2-thread-26,5,main]>
> #<Thread Thread[pool-2-thread-24,5,main]>

was generated using the latter defn (the one that captures
Thread/currentThread outside the send).

-- 
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