store/[org.clojure/clojure "1.8.0"] clj::clojure.core/pmap

Official Documentation

Add notes
Arities
==================================================
   [f coll]
   [f coll & colls]

Docstring
==================================================
  Like map, except f is applied in parallel. Semi-lazy in that the
  parallel computation stays ahead of the consumption, but doesn't
  realize the entire result unless required. Only useful for
  computationally intensive functions where the time of f dominates
  the coordination overhead.

Source

(defn pmap
  "Like map, except f is applied in parallel. Semi-lazy in that the
  parallel computation stays ahead of the consumption, but doesn't
  realize the entire result unless required. Only useful for
  computationally intensive functions where the time of f dominates
  the coordination overhead."
  {:added "1.0"
   :static true}
  ([f coll]
   (let [n (+ 2 (.. Runtime getRuntime availableProcessors))
         rets (map #(future (f %)) coll)
         step (fn step [[x & xs :as vs] fs]
                (lazy-seq
                 (if-let [s (seq fs)]
                   (cons (deref x) (step xs (rest s)))
                   (map deref vs))))]
     (step rets (drop n rets))))
  ([f coll & colls]
   (let [step (fn step [cs]
                (lazy-seq
                 (let [ss (map seq cs)]
                   (when (every? identity ss)
                     (cons (map first ss) (step (map rest ss)))))))]
     (pmap #(apply f %) (step (cons coll colls))))))

Example 1

Edit
;; create a function that simulates a long running process using Thread/sleep
(defn long-running-job [n]
  (Thread/sleep 3000) ; wait for 3 seconds
  (+ n 10))

;; used `doall` to eagerly evaluate `map`, which evaluates lazily by default

;; notice that the total elapse time is almost 3 secs * 4
(time (doall (map long-running-job (range 4))))
;; > "Elapsed time: 11999.235098 msecs"
;; => (10 11 12 13)

;; notice that the total elapse time is almost 3 secs only
(time (doall (pmap long-running-job (range 4))))
;; > "Elapsed time: 3200.001117 msecs"
;; => (10 11 12 13)

Example 2

Edit
;; pmap is implemented using Clojure futures.  See examples for 'future'
;; for discussion of an undesirable 1-minute wait that can occur before
;; your standalone Clojure program exits if you do not use shutdown-agents.

Example 3

Edit
;; This function operates just like map.  See
;; clojure.core/map for more details.
(pmap inc [1 2 3 4 5])
;; => (2 3 4 5 6)

Uses on crossclj