Skip to content

clojure.core/pmap

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 5 Runnable: 3
([f coll] [f coll & colls])

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.

Examples

by gstamp on
by OnesimusUnbound on . May have evaluation errors.
by jafingerhut on
by cljlc on . May have evaluation errors.
by cljlc on

Note by belun

for insight into how pmap does stuff see this presentation: "From Concurrency to Parallelism", by David Edgar Liebke @ http://incanter.org/downloads/fjclj.pdf

Note by reborg

The following can be used to understand how many threads pmap runs at once (assuming tasks are roughly the same computational cost). The min level correspond to the situation where the consumer is slower than the producer, while the max level is when the consumer is faster than the producer:

  • When the sequence is not chunked (for example subvec) the min parallelism is 1 and the max parallelism is (+ 2 N-cores). Example: with 12 cores, (doall (pmap #(Thread/sleep %) (subvec (into [] (range 1000)) 0 999))) keeps 12+2 threads busy.
  • In case of chunked sequences (vast majority are size 32), the min parallelism is (min chunk-size (+ 2 n-cores)), while the max amount is equal to (+ chunk-size 2 N-cores). Example: with 12 cores, (doall (pmap #(Thread/sleep %) (range 1000))) keeps 12+2+32 threads busy.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.