Skip to content

Instantly share code, notes, and snippets.

@na-ka-na
Created December 8, 2013 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save na-ka-na/7863249 to your computer and use it in GitHub Desktop.
Save na-ka-na/7863249 to your computer and use it in GitHub Desktop.
; MPI kind macros
(defmacro BLOCK_LOW [i p n] `(int (/ (* ~i ~n) ~p)))
(defmacro BLOCK_HIGH [i p n] `(- (BLOCK_LOW (+ 1 ~i) ~p ~n) 1))
(defmacro BLOCK_SIZE [i p n] `(- (BLOCK_LOW (+ 1 ~i) ~p ~n) (BLOCK_LOW ~i ~p ~n)))
(defmacro BLOCK_ONWER [j p n] `(int (/ (- (* (inc ~j) ~p) 1) ~n)))
(defn partition-work
[p coll]
(let [s (seq coll)
n (count s)]
(loop [w [] s s i 0]
(if (< i p)
(let [block-size (BLOCK_SIZE i p n)]
(recur (conj w (take block-size s)) (drop block-size s) (inc i)))
(seq w)))))
(defn npmap [p f coll]
(apply concat
(pmap #(doall (map f %))
(partition-work p coll))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment