On 18/08/12 13:57, Michael Gardner wrote:
  Until the reducers library is ready, you could try something like this (no 
guarantees that this is an optimal implementation!):

(defn with-thread-pool* [num-threads f]
   (let [pool (java.util.concurrent.Executors/newFixedThreadPool num-threads)]
     (try (f pool)
       (finally
         (when pool (.shutdown pool))))))

(defmacro with-thread-pool [[name num-threads] & body]
   `(with-thread-pool* ~num-threads (fn [~name] ~@body)))

(defn pmap-pool [f coll]
   (with-thread-pool [pool (.. Runtime getRuntime availableProcessors)]
     (doall
       (map #(.get %)
         (.invokeAll pool
           (map (partial partial f)
             coll))))))


Hi Michael,

Unfortunately I get exactly the same performance with pmap when using the above code... and again 2 of my cpus are sitting around waiting! If use pmap or map-pool on all levels i get almost 100% utilisation of cpu but nothing useful happens!!! anyway, I'll have a look at reducers!
thanks for the snippet anyway!

Jim

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