<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
I have a number of compute-bound graphics programs written in Haskell.
(Fractal generators, ray tracers, that kind of thing.) GHC offers
several concurrency and parallelism abstractions, but what's the best
way to use these to get images rendered as fast as possible, using the
available compute power?<br>
<br>
(OK, well the *best* way is to use the GPU. But AFAIK that's still a
theoretical research project, so we'll leave that for now.)<br>
<br>
I've identified a couple of common cases. You have a 2D grid of points,
and you want to compute the value at each point. Eventually you will
have a grid of <i>pixels</i> where each value is a <i>colour</i>, but
there may be intermediate steps before that. So, what cases exist?<br>
<br>
1. A point's value is a function of its coordinates.<br>
<br>
2. A point's value is a function of its previous value from the last
frame.<br>
<br>
3. A point's value is a function of <i>several</i> points from the
last frame.<br>
<br>
How can we accelerate this? I see a few options:<br>
<br>
- Create a spark for every point in the grid.<br>
- Create several explicit threads to populate non-overlapping regions
of the grid.<br>
- Use parallel arrays. (Does this actually works yet??)<br>
<br>
I'm presuming that sparking every individual point is going to create
billions of absolutely tiny sparks, which probably won't give great
performance. We could spark every line rather than every point?<br>
<br>
Using explicit threads has the nice side-effect that we can produce
progress information. Few things are more frustrating than staring at a
blank screen with no idea how long it's going to take. I'm thinking
this method might also allow you to avoid two cores tripping over each
other's caches.<br>
<br>
And then there's parallel arrays, which presumably are designed from
the ground up for exactly this type of task. But are they usable yet?<br>
<br>
Any further options?<br>
<br>
</body>
</html>