Created
December 8, 2013 20:11
-
-
Save na-ka-na/7863249 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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