Hi everyone- I'm a new Clojurist trying to understand how to make use of Clojure parallelism... I wrote this simple program that calculates the number of prime numbers in a number range. It is purposely inefficient:
(defn prime [a] (not-any? #(integer? (/ a %)) (range 2 a))) (defn primes [a b] (print "there are" (count (filter prime (range a b))) "primes between" a "and" b) (prn)) user=> (time (primes 1 40000)) there are 4204 primes between 1 and 40000 "Elapsed time: 21937.651015 msecs" Here, I calculate two such ranges in sequence with the map command: user=> (time (dorun (map #(primes %1 %2) [1 40000] [40000 60000]))) there are 4204 primes between 1 and 40000 there are 1854 primes between 40000 and 60000 "Elapsed time: 48624.117451 msecs" Next, I run the same calculation with the pmap command: user=> (time (dorun (pmap #(primes %1 %2) [1 40000] [40000 60000]))) there are 4204 primes between 1 and 40000 there are 1854 primes between 40000 and 60000 "Elapsed time: 49900.961506 msecs" To my befuddlement, the 'pmap version runs slower than the 'map version... This seems to clearly indicate that this code is not taking advantage of the second core of my Core2 Duo processor... Can someone help me understand what I'm doing wrong? Thanks in advance! Conrad Barski, M.D. Additional specs on my environment: Dell Inspiron 1420 Ubuntu Ibex Core2 Duo c...@2.20ghz Java(TM) SE Runtime Environment (build 1.6.0_10-b33) Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---