Wednesday, December 22, 2010

Using Amazon EC2 to speed up matlab optimisation III: Getting it all working together, and some speed results

OK, this is the final part of the tutorial
In part 1, you should have created the matlab server to listen for commands. In part 2, you should have started an EC2 instance, installed the necessary software, and saved it for future use.
In part 3, we will write a client in Matlab to send off optimisation jobs to the servers to run and get back the results.
I have implemented this as a matlab class, @socket_client.
The code is available to download
The constructor (socket_client.m) just takes as an argument the location of the ssh key for accessing the machines. To use the default location, the constructor is run as follows:
s = socket_client();
The next step is to update the server list: [s,servers] = updateserverlist(s);
The program updateserverlist.m calls the program findinstances.m, which uses the program ec2-describe-instances, which should have been installed as part of the EC2 API. In this way, all servers that have been started (as described in part 2) will be utilised.
Then a set of jobs can be constructed, for example: % Set up 20 jobs for k=1:20 joblist(k).command = codes.decompose; joblist(k).arguments = {a(k).time,a(k).vel,[],[],[]}; end
Then finally they can be run: [results,finishtimes] = runjobs(s,joblist,1);
The runjobs code keeps track of what each server is doing. When a job is finished it saves the results, and assigns it the next job from the queue.
And that is it! I'll be happy to hear if you get this working yourself or have an alternative solution to this problem.


  1. Thanks For Sharing Your solution.
    But i can't understand where i should introduce my matlab function to sucket_client.
    I think joblist will do this but how?

  2. hello .. im doing final year comm dept.. i want do my project is using matlab cloud computing .. give any idea ?

  3. Hi Fifa,

    In socket_client, you will just give the name of the function (e.g. instead of codes.decompose) and the arguments. The function to do the actual work needs to go in the server (see part 1 of the tutorial).