multithreading - Lightweight parallel Clojure for loop on Incanter matrix? -


i have function uses for loop modify elements of matrix. element-wise function not huge, unsure best way deal this. want have 1 thread each core of machine (automatically detected) execute these. ideally, balance execution based on core workload. have looked creating custom thread pools receiving workers, not sure if work. pmap seems might useful, saw in thread coordination overhead signficant if every single operation future. thoughts how approach this? code below, links afterwards.

(defn alter-matrix! [matrix]   (let [row-count (nrow matrix)     col-count (ncol matrix)]  ; iterate through each element coordinates. (for [x (range row-count)       y (range col-count)]    ; calculate whether element altered.   (let [event (rand)]      ; 50% chance of alteration.     (if (< event 0.50)        ; unsafely set new element altered version.       (.setquick matrix x y                    ; return altered form of element.                  (alter-element (.getquick matrix x y))))))))  (defn alter-element [element] (let [selector (rand-int 1 4)]   (cond (= 1 selector) 1.0 (= 2 selector) (* 2.0 element) (= 3 selector) (* 0.5 element)))) 

parallel doseq clojure http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html better alternative pmap in clojure parallelizing moderately inexpensive functions on big data?


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -