[racket] Concurrent execution

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Oct 3 15:57:30 EDT 2011

Four hours ago, jukka.tuominen at finndesign.fi wrote:
> 
> Wow, that's great Sam!
> 
> I tried to create a simple test around it (below), but it's hard to find a
> pattern in the results. A few notes, though:
> 
> - The results vary a great deal from run to run
> - 'Plain map' seems to do things in parallel itself!?
>   (by looking at the System Monitor during the test run)
>   This may paralyze secondary parallelizing :)
> - Plain map does usually better with short lists. No wonder.
> - The amount of distribution should be related to the available
>   number of HW processors; not the more the merrier, obviously.

Using factorial to measure speed is not a good idea -- since with
bigger numbers much of the time is spent on GC work for the bignums.
Also, it looks like you were timing the printouts too, and with big
numbers that can take a considerable amount of time too.

Here's a short test using a factorial -- note that pmap takes a bit
more overall cpu time, but the real time is much shorter.

-> (define (pmap f xs)
     (map touch (map (λ (x) (future (lambda () (f x)))) xs)))
-> (define (fib n) (if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
-> (time (map fib '(35 36 37 38)))
cpu time: 5088 real time: 5098 gc time: 0
'(9227465 14930352 24157817 39088169)
-> (time (pmap fib '(35 36 37 38)))
cpu time: 5106 real time: 2292 gc time: 0
'(9227465 14930352 24157817 39088169)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!



Posted on the users mailing list.