Hi Zak,

I tried your example on my i7 (4 physical cores, 8 logical); here are
the results -

1:298 user=> (time (do (doall (map fac (take 10 (repeat 50000))))
nil))
"Elapsed time: 54166.665145 msecs"

1:300 user=> (time (do (doall (pmap fac (take 10 (repeat 50000))))
nil))
"Elapsed time: 27418.26344 msecs"

With map CPU usage ~12.5%, with pmap (10 threads) ~50% average.

But when I change the fac function to say -

(defn fac
  [n]
  (let [n (* n 1000)]
    (loop [i 0]
      (when (< i n)
        (* 2 2)
        (recur (inc i))))))

1:308 user=> (time (do (doall (map fac (take 10 (repeat 50000))))
nil))
"Elapsed time: 48507.220449 msecs"

1:309 user=> (time (do (doall (pmap fac (take 10 (repeat 50000))))
nil))
"Elapsed time: 9320.92417 msecs"

With map CPU usage ~12.5%, with pmap (10 threads) ~95% average.

So I think it may be something to do with really BigIntegers in your
original fac, but I can't be sure.  The point is that the original fac
somehow doesn't consume the entire CPU even with 10 threads ?!  If you
find out the reason why let me know.

Also I didn't spend much time with your npmap function, but it seems
like a nice idea.  One observation - partition-all is not very good at
dividing up work to be done.  For example suppose you want to divide
up a coll of length 9 into 4 threads, there is no way to do that with
the partition-all directly -

(1:335 user=> (clojure.core/partition-all 2 (range 9))
((0 1) (2 3) (4 5) (6 7) (8))
1:336 user=> (clojure.core/partition-all 3 (range 9))
((0 1 2) (3 4 5) (6 7 8))

Something like this might be better suited (https://gist.github.com/
54313ab02d570204393b) -
1:338 user=> (partition-work 4 (range 9))
((0 1) (2 3) (4 5) (6 7 8))

The above partition-work is based on ideas which I got from MPI
programming a while back.

- Thanks

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