Ateji PX

I recently came across this technology called Ateji PX. Fundamentally it’s Java extended with some parallel constructs. It is really easy to learn and provides a much cleaner programming paradigm than explicit thread creation. The concept is pretty simple. You can execute statements in parallel just by writing:

[ doSomeStuff(); || doSomeOtherStuff(); ]

Anything that comes after these two statements will wait for both statements to finish. No need to get hold of threads, invoke join and pass arguments. Ateji will also take care of passing parameters, handling exceptions etc.

int x,y;
[x = calculateX(); || y = calculateY();]
return x + y;

This will calculate x and y in parallel and afterewards return their sum.

For me, the killer feature of Ateji is the parallel for statement.

float[] foo = new float[100];
for || (int x : 0 .. foo.length) {
  foo[i] = calculateFoo(x);
}

This will calculate the function foo for all the values of x ranging from 0 to 99.

Now if your array happens to be made of 1000000 elements. Doing a parallel loop over it would create 1000000 threads. Since thread creation in Java is still expensive, this would add way too much overhead. The authors of Ateji hae taken this into consideration and they’ve added the possibility to annotate your loop like this:

float[] foo = new float[100];
for || (#BlockCount(30), int x : 0 .. foo.length) {
  foo[i] = calculateFoo(x);
}

Now this will limit the number of threads to 30. If your threads never block, setting this number slightly above the number of CPU cores will ensure that you take full advantage of parallelism.

I wrote a simple implementation of raymarching in order to test the performance improvement and the difference is really noticeable.

Image

when parallelism is disabled the ray tracing algorithm looks like a slideshow. When I enable it, it’s smooth as a baby’s bottom. Theoretically the speedup shouldn’t be more than 4x, but it really feels rewarding having achieved this with just a couple of lines of code:

 for || (#BlockCount(30), int x : (int) resolution.x, int y : (int) resolution.y) {
   image[x][y] = pixelFunction.getPixelColor(time, 2*x/resolution.x - 1, -2*y/resolution.y+1);
 }

In this post I’ve just scratched the surface of what Ateji PX offers. They have message passing primitives allowing you to use the actor model, they have parallel list comprehensions and reductions with the ability to define your own monoids. They are also working on an implementation that allows execution on the GPU. Think of running Java on thousands of cores on your gaming PC. However the harsh reality is that the company behind Ateji has closed because they could not generate a “steady stream of revenue“. This reminds me of the many situations in industry where the better technology looses for non technical reasons (Betamax vs VHS). I hope the community keeps Ateji PX alive because it makes Erlang & co look like toys for children.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s