小编Spe*_*pel的帖子

在Clojure中使用pmap并行化合并排序。程序在结束前会挂起〜1分钟,然后终止

我正在用Clojure编写一个程序,该程序从文本文件10000.txt(具有10k,无符号整数)接受输入。然后,我将该列表传递到我的归类排序函数中(单个线程,2、4、8、16、32线程)。

当我运行该程序时,通过键入“ clojure test.clj”,它会输出每个函数的经过时间,但该程序不会终止。

它像正在等待输入或即将输出其他内容一样挂在那里。然后大约1分钟后,程序最终终止。幕后一定有事发生。输入后终止程序有什么想法/我需要做什么?

程序的输出(终止之前),这是挂起大约1分钟的地方

终端输出图片

(use 'clojure.java.io)
(require '[clojure.string :as str])

;Read file and store into numbers, as a string
(def numbers (slurp "10000.txt"))

;Parse the string 'numbers', ignore the spaces 
;and save the result into x1 (a lazy-seq of integers)
(def x1 (map #(Integer/parseInt %) (str/split numbers #"\s+")))

;Function that performs the operation of merge sort algorithm
(defn merge-lists [left right]
  (loop [head [] L left R right]
    (if (empty? L) (concat head R)
        (if (empty? R) (concat …
Run Code Online (Sandbox Code Playgroud)

concurrency multithreading clojure terminate pmap

1
推荐指数
1
解决办法
96
查看次数

标签 统计

clojure ×1

concurrency ×1

multithreading ×1

pmap ×1

terminate ×1