From 52b7cb37bbee971ca90d424f141bb489ab23d745 Mon Sep 17 00:00:00 2001 From: Andreas Olsson Date: Tue, 27 Dec 2016 22:10:15 +0100 Subject: [PATCH] Add files via upload --- pmap.rkt | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/pmap.rkt b/pmap.rkt index 55ba118..49fc70e 100644 --- a/pmap.rkt +++ b/pmap.rkt @@ -1,33 +1,28 @@ #lang racket +;pmap is a parallel concurrent map function. +;its inspired of Clojures pmap. + (require racket/future) -(require racket/future - future-visualizer) -(define f (format "~a" (futures-enabled?))) -(println (string-append "futures enabled: " f)) +(provide pmap1) +(provide pmap2) -(define pc (format "~a" (processor-count))) -(println (string-append "processor-count: " pc)) - - -(provide pmap) -(provide pmapTwo) - -(define (pmap func alist) ; Sort of pmap - (let* ([f (for/list ([a alist]) (future (lambda () (func a ))) )]) - (for/list ([i f]) (touch i))) +(define (pmap1 func alist) ; pmap for one list + (map touch + (for/list ([a alist]) + (future (lambda () (func a ))) + )) ) -;(visualize-futures ; If function isnt heavy enuf you will get an error, try comment out! -(pmap (lambda (x)(car x)) '((a b)(c d)(e f))) -;) +;(pmap1 (lambda (x)(car x)) '((a b)(c d)(e f))) ; a test -(define (pmapTwo func alist blist) ; Sort of pmap - (let* ([f (for/list ([a alist][b blist]) (future (lambda () (func a b))) )]) - (for/list ([i f]) (touch i))) + +(define (pmap2 func alist blist) ; pmap for two lists + (map touch + (for/list ([a alist][b blist]) + (future (lambda () (func a b))) + )) ) -;(visualize-futures ; If function isnt heavy enuf you will get an error, try comment out! -(pmapTwo (lambda (x y) (* x y)) '(1 2 3 4 5 6) '(1 2 3 4 5 6)) -;) \ No newline at end of file +;(pmap2 (lambda (x y) (* x y)) '(1 2 3 4 5 6 7 8 9) '(1 2 3 4 5 6 7 8 9)) ; a test \ No newline at end of file