I suspect that (rand), which calls java.lang.Math.random(), is a synchronized method, meaning that if you try to call it from many parallel threads, even those on physically separate cores, will execute one at a time. Things could even take more time if you try to execute them in parallel than sequentially, due to lock contention overhead that does not occur if you try to execute them sequentially.
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html#random%28%29 Try doing something besides (rand) in your function t that does not use locking or synchronized methods. You might also experiment with having no Thread/sleep call in there, but that might be part of what you are trying to learn the behavior of. I'm not sure. Andy On Sat, Aug 27, 2011 at 6:16 PM, artg <artgittle...@gmail.com> wrote: > I understand that pmap needs to have big chunks to overcome the > overhead but I don't understand my results > > (defn t [m] > (dotimes [i m] (rand)) > (Thread/sleep 1000)) > > (defn testmap [f n m] > (time (doall (f t (repeat n m))))) > > user=> (testmap map 8 100) > "Elapsed time: 8108.174484 msecs" > (nil nil nil nil nil nil nil nil) > user=> (testmap pmap 8 100) > "Elapsed time: 1006.797146 msecs" > (nil nil nil nil nil nil nil nil) > user=> (testmap pmap 8 1000000) > "Elapsed time: 3781.967909 msecs" > (nil nil nil nil nil nil nil nil) > user=> (testmap map 8 1000000) > "Elapsed time: 8544.896008 msecs" > (nil nil nil nil nil nil nil nil) > user=> (testmap map 8 10000000) > "Elapsed time: 10663.057874 msecs" > (nil nil nil nil nil nil nil nil) > user=> (testmap pmap 8 10000000) > "Elapsed time: 29525.579612 msecs" > (nil nil nil nil nil nil nil nil) > > I'm using an i7 with 8 processors so the Thread alone mostly gives an > 8-fold speedup. Calling (rand) more times impacts pmap even though I > map and pmap on a list of size 8 to spawn eight functions each with a > lot of work. > > -- > 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