<meta charset="utf-8"><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; "><div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; ">Hi Stephen, </span></div>
<div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; "><br></span></div><div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; ">I took the code you posted and tried filling in the bodies with my own code, but wasn&#39;t able to crash DrRacket in the way you describe.  Could you post/send me the actual code you were using?  </span></div>
<div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; "><br></span></div><div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; ">Thanks, </span></div>
<div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; ">James </span></div><div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; "><br>
</span></div><div><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(68, 68, 68); font-family: arial, sans-serif; font-size: 13px; "><br></span></div>On May 11, 2011, at 3:23 PM, Robby Findler wrote:<br>
<br>&gt; You might try futures. Do read the guide first, of course.<br><br>I&#39;ve tried some simple experiments.<br><br>The function in question iterates over every pixel of an image being<br>constructed:<br>       (for* ((y (in-range 0 height))<br>
                 (x (in-range 0 width)))<br>            ; set the (x,y) pixel in the bitmap to be the result of a<br>function call on x and y<br>            )<br><br>I wrote another version that parallelizes the rows:<br>
       (touch-all (for/list ((y (in-range 0 height)))<br>                                 (future (lambda () (for ((x (in-range<br>0 width)))<br><br>; set the (x,y) pixel as above<br>                                               ))))<br>
       (define (touch-all futures)<br>               (for ((f futures)) (touch f)))<br>This version occasionally crashes DrRacket, but usually runs in about<br>twice the time of the non-futures version.<br><br>I wrote another version that parallelizes the columns:<br>
       (for ((y (in-range 0 height)))<br>               (touch-all (for/list ((x (in-range 0 width)))<br>                                       (future (lambda ()<br>                                                       ; set the (x,y)<br>
pixel as above<br>                                                       ))))))<br>I don&#39;t think I&#39;ve ever gotten this version to run without crashing<br>DrRacket, so I have no timing data.<br><br>I wrote another version that parallelizes both rows and columns:<br>
       (touch-all (for*/list ((y (in-range 0 height))<br>                                            (x (in-range 0 width)))<br>                               (future (lambda ()<br>                                               ; set the (x,y) pixel as above<br>
                                       ))))<br>This ran once without crashing, but it produced a wrong answer, and I<br>didn&#39;t get the timing data.  Every other time I&#39;ve tried it, DrRacket<br>has crashed.<br><br>
The likelihood of crashing seems to be lower if width and height are smaller.<br><br><br><br><br>I then tried some simpler, smaller, non-image examples:<br><br>(define nums (build-list 1000 (lambda (x) x))<br><br>(time (touch-all (map (lambda (x) (future (lambda () (sqrt x)))) nums)))<br>
vs.<br>(time (map sqrt nums))<br><br>I can&#39;t tell how much slower the former is than the latter, because<br>I&#39;ve never gotten the latter to exceed 0 ms :-)<br>But at least the futures version has CPU time &gt; real time, which<br>
suggests there&#39;s some parallelization going on.<br><br><br><br><br><br>So I figured &quot;maybe you&#39;re not supposed to use more futures than you<br>have processors.&quot;<br>I&#39;m running on a machine with 4 parallel processors, according to<br>
(processor-count).<br>So I tried something with only 3 futures:<br>(time (touch-all (map (lambda (x) (future (lambda () (map (lambda (y)<br>(* x y)) nums)))) &#39;(1 2 3)))<br>as compared with a non-futures version<br>(time (map (lambda (x) (map (lambda (y) (* x y)) nums)) &#39;(1 2 3)))<br>
The futures version takes about twice as long as the non-futures<br>version.  But again, CPU time &gt; real time, which suggests some<br>parallelization.<br><br><br>I suspect that futures would be more useful if each of the tasks were<br>
bigger; I should try some more experiments with more complex tasks.<br><br>Stephen Bloch<br><a href="mailto:sbloch@adelphi.edu" style="color: rgb(34, 34, 34); ">sbloch@adelphi.edu</a></span>