On Jan 21, 8:56 am, Perry Trolard <trol...@gmail.com> wrote: > If I understand what you did correctly, the reason it worked for you > is that Rich committed a fix to SVN in the meantime!
Awesome, real-time fix! > > The last (count result-p) call takes a few seconds (probably > > because there's a one-to-one mapping of tasks to sequence > > elements) but it finishes. > > That's right, just for the record, using pmap to map inc across a > collection of integers -- or to do any similarly low-cost computation > -- is a *bad* idea. Map will always be faster -- in my casual tests > with inc, pmap is slower by an order of magnitude. (But pmap should > still compute the value, & inc was an easy way to make a reduction for > bug reporting...) *nods* if you want parallelism for a low-cost computation with pmap, then it might be better to divide a Java vector into subvectors and map over chunks of ranges. However, it's not immediately obvious how to do this. For example, on my fairly modern dual-core machine: * I have a function make-test-array that produces a filled-in array of doubles * areduce-part is like areduce, but works on a range of vector indices, rather than a vector user> (let [v (make-test-array 1000000)] (time (+ (areduce-part v 0 500000) (areduce-part v 500000 1000000)))) "Elapsed time: 6.454977 msecs" 4.999995E11 user> (let [v (make-test-array 1000000)] (time (reduce + (pmap (fn [[start end]] (areduce-part v start end)) [[0 500000] [500000 1000000]])))) "Elapsed time: 9.638913 msecs" 4.999995E11 I know that "time" isn't counting test array creation time: (let [v (. Thread sleep 1000)] (time 42)) "Elapsed time: 0.020304 msecs" 42 It could be that the two threads are contending over the Array object reference (Java arrays aren't pointers). Is there a nice way to create "subvector" objects that only reference the underlying memory and not the parent array object? mfh --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---