I'm looking into this now, but there are a few modifications you can make to eliminate some blocking calls, namely:
sph-list is a list, and you are using for/fold to iterate over the elements in the list (inside a future). This is problematic for a number of reasons; instead, you could convert it to a vector (or just change your definition to use a vector) and change `ray-cast' accordingly: (define (ray-cast x y object-list) (let ([view-ray (screen-ray x y)]) (define closest-int (int-res #f 10000.0 null-point)) (for ([i (in-range 0 (vector-length object-list))]) (define obj (vector-ref object-list i)) (set! closest-int (get-closer-res closest-int (hit-sphere3D view-ray obj)))) closest-int)) Also, there are two places where I think you may have forgotten to use flonum primitives (on lines 99 and 100) -- just change `sqrt' to `flsqrt', as you have done elsewhere in the code. This doesn't eliminate all the blocking behavior, however -- I still see a few `values' blocking calls, and allocation as well. I'll spend some more time looking through it and report back to you. Cheers, James Date: Fri, 22 Feb 2013 00:03:28 +0300 > From: Dmitry Cherkassov <dcherkas...@gmail.com> > To: users@racket-lang.org > Subject: [racket] values primitive blocks future execution > Message-ID: > <CAN0j1dRCGY7A2WxXBYXP= > jblntw_-l3o7eoyjvd1vtab+qd...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi list. > I've been doing a simple ray tracer[1] and decided to parallelize it using > futures. > > I've tried to use flonums everywhere and added (in-range) to loops [3] > (over x and y coordinates). > > The problem is that execution of future is blocked seriously. > (apparently by the value primitive) [2] > > Are there any ideas why it doesn't work? > > I use racket v5.3.3. > > [1] Complete source code: http://pastebin.com/EGSzR1Tv > > [2] Future visualizer screenshot: http://ompldr.org/vaGpiaQ > Invoked via > (require future-visualizer) > (visualize-futures (run-no-render)) > > [3] Source code for main loop: > (define (render-scene-dummy object-list) > (let* ([f (future > (lambda () > (for* ([x (in-range (/ screen-width 2))] > [y (in-range screen-height)]) > (let* ([ray-res (ray-cast x y object-list)] > [pix-col (point-col (int-res-p ray-res))]) > #t)) > ))]) > > (for* ([x (in-range (/ screen-width 2) screen-width)] > [y (in-range screen-height)]) > (let* ([ray-res (ray-cast x y object-list)] > [pix-col (point-col (int-res-p ray-res))]) > #t)) > (touch f))) > > > > -- > With best regards, > Dmitry > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://lists.racket-lang.org/users/archive/attachments/20130222/6e2262a8/attachment-0001.html > > > >
____________________ Racket Users list: http://lists.racket-lang.org/users