Add files via upload

This commit is contained in:
Andreas Olsson 2016-12-27 22:10:15 +01:00 committed by GitHub
parent 1b258bc962
commit 52b7cb37bb

View File

@ -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))
;)
;(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