Clojure 有没有办法控制pmap使用的线程数?
我正在使用pmap对clojure进行一些性能测试,我希望能够控制使用pmap的线程数。我知道当使用类似OpenMP的东西时,可以使用omp\u set\u num\u threads()设置线程数。我想知道clojure中是否会有类似的内容。以下是Clojure 有没有办法控制pmap使用的线程数?,clojure,Clojure,我正在使用pmap对clojure进行一些性能测试,我希望能够控制使用pmap的线程数。我知道当使用类似OpenMP的东西时,可以使用omp\u set\u num\u threads()设置线程数。我想知道clojure中是否会有类似的内容。以下是pmap的代码: (defn pmap "Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of
pmap
的代码:
(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."
([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))))
如您所见,pmap
将所有可用的处理器循环使用。所以,不,没有办法设置线程数。。。但是您可以编写自己的pmap
,它将提供这样的功能