Monday, May 23, 2016

Easy Parallel Computing with Old Android Phones

I have some relatively old Android phones lying around (including the Nexus 4 with a broken screen I rooted) and I wanted to cluster them together in some way to see what they were capable of. But the problem was that none of them had the same platform. They all had different Android flavors and different permissions. So I made a few crucial design decisions up front to make this method of clustering as compatible with everything as possible. Here's the outline of how this is going to work.

  • Both the master and the workers will be running on the same regular Android application. It won't have any special permissions.
  • The devices will form an adhoc network over Bluetooth to transmit messages.
  • The parallel code will be Javascript and run in a WebView container. A Javascript Interface will be implemented to facilitate the message transfer from the Javascript to the app.
For this to work, we need to make up some kind of API for this Javascript code to work with. I created a very simple one very quickly that should cover most use cases. It supports process numbering, sending, receiving, and broadcasting. All of the messages will be in JSON format. Here's what I imagine a parallel program will look like on this platform.

function start(numproc,rank) {
    if(rank==0) {
        var contents = "Hello there";
        var dest = 1;
        var label = 0;
        CONTROL.send(contents,dest,label);
    }
}

function recv(contents,source,label,isbroadcast) {
    CONTROL.send(contents,source,label);
}

This is an example program that echos messages back to the root process (which we'll always say is processor #0).

This is a very incomplete implementation but it shows that it can be done with some finagling and better message control. This is just a proof of concept, better revisions would need better message routing as well as a more efficient means of determining rank and better communications (gather, scatter, etc.) 

So yeah, feel free to experiment with this. It's by no means complete, but it sorta kinda works well enough.

No comments:

Post a Comment