Sunday, November 05, 2006

Matlab: Lack of multithread

In my everyday work I use Sun-Fire-V440 server. The main characteristics of this machine is the fact that it contains four processors, which is great. I use it mainly
to write image processing algorithms in Matlab 7.0, which are usually very time consuming and require wast amount of resources.

Despite the power of this machine, I cannot use it fully due to Matlab. This is because by definition it is only singe threaded application and there is on way of creating few threads. This of course causes that even thought given algorithm or application could be divided to e.g. four parallel threads, it cannot be done due to Matlab.

This drawback of Matlab is really frustrating, because Matlab uses fully only one processor out of four. On the other words, while one processors is fully loaded, three others do not do anything useful. As a result of that, my computations take four times more time to finish, compared with the situation if I could use all four processors in Matlab.

For instance, sometimes I write something in ANSI C, and there is no problem of creating threads; hence, my algorithms in ANSI C are four time faster than the same single threat algorithms on this Sun server, because they use all four processors.

Nevertheless, using single thread Matlab on four-processors server has some advantage. The main advantage of this is that I can run four separate Matlab instances, which I do often. For example, if I have one thousand images to process, I can run four matlab in four consoles, and I can tell that the first instance processes images from 1 to 250, second one processes 251 to 500, third and forth one 501-750 and 751 to 1000 respectively.
Moreover, I can run four Matlabs processing 1000 images each, but with different parameters. Consequently I can check my program with four different parameters and check their impact on the results simultaneously, rather than execute one version of program by another. This also uses four processors and I can do my work four times faster than on single Matlab instance.

Thanks to this, even though my application is single threaded, I can process 1000 images four time faster using four Matlabs than using one Matlab. This way, 100% of computation power of my server is used, and all four processor are doing something useful.

Below I present screen from top command, showing four Matlabs using in summary almost 100% of CPU power of my Sun.

No comments:

Post a Comment