Parallel map applies a function to collection elements concurrently while preserving the ordered, lazy-sequence interface of map. In Clojure, pmap is useful for independent, sufficiently expensive transformations, but parallelism does not automatically improve every workload. section 9.1.5 section 9.1
Its contract and practical behavior are:
- Accepts a function and one required sequential collection, plus optional collections; the function arity must match the number of collections. section 9.1.5
- Returns a lazy sequence in input order, even though transformations execute in parallel through futures. section 9.1.5
- Raises ArityException without a collection and has no transducer version. section 9.1.5
- Can process work in chunks; chunking may reduce overhead, while cheap functions or poorly balanced tasks can make pmap slower than map. section 9.1.5
Ordered results with parallel evaluation
(pmap + (range 10) (range 10)) ;; (0 2 4 6 8 10 12 14 16 18) (defn f [x] (Thread/sleep (+ (* 10 x) 500)) (println (str "done-" x)) x) (def s (pmap f (range 100))) (first s) ;; 0 (take 2 s) ;; (0 1) The side-effect messages can appear as work completes, while the realized sequence remains ordered. section 9.1.5
Choosing granularity
Benchmarks show that pmap can lose to map for cheap operations such as inc, while partitioning work into larger groups can improve a costly computation. Another timing example shows uneven sleep durations completing far faster after sorting the work before pmap.
Listing 9.5. → Parallel computation, Lazy sequences
(pmap ([f coll]) ([f coll & colls])) (pcalls [& fns]) (pvalues [& exprs])
Browse the compact signatures for pmap, pcalls, and pvalues. section 9.1.5

