www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 52b7cb37bbee971ca90d424f141bb489ab23d745
parent 1b258bc9627ea5b415818d1f2c1a8e750b2481b1
Author: Andreas Olsson <photoguy.apo@gmail.com>
Date:   Tue, 27 Dec 2016 22:10:15 +0100

Add files via upload
Diffstat:
Mpmap.rkt | 43+++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/pmap.rkt b/pmap.rkt @@ -1,33 +1,28 @@ #lang racket -(require racket/future) -(require racket/future - future-visualizer) - -(define f (format "~a" (futures-enabled?))) -(println (string-append "futures enabled: " f)) - -(define pc (format "~a" (processor-count))) -(println (string-append "processor-count: " pc)) +;pmap is a parallel concurrent map function. +;its inspired of Clojures pmap. +(require racket/future) -(provide pmap) -(provide pmapTwo) +(provide pmap1) +(provide pmap2) -(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