(require '[clojure.core.reducers :as r]) ;; Simplest way to do parallel computation: pmap ;; Note: reduce isn't parallel (reduce + (pmap inc (range 100000000))) ;; Clojure reducers: compute in paralllel ;; They partition the sequence to place on different cores. ;; They visit each element once, applying all the required ;; finctions (in this case, inc and a choice based on even?) (r/fold + (r/filter even? (r/map inc [1 1 1 2]))) ;(time (reduce + (filter even? (map inc (range 100000000))))) ;(time (r/fold + (r/filter even? (r/map inc (range 100000000))))) ;(reduce +' (range 10000000000)) ;; "Elapsed time: 598499.828637 msecs" ;(time (reduce +' (range 10000000000N))) ;;"Elapsed time: 619939.91323 msecs": ;(time (r/fold +' (range 10000000000N)))
CSci 4651 course web site.
The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.