Tuesday, May 19, 2009

Running Matlab through a ssh tunnel

It is (un)common in a Computer Center environment to run applications on a remote server and see the graphical output on the local machine. This is usually achieved using X11 forwarding over ssh.

I had to set up Matlab R2009a on a brand new SUN blade server and make it available to users through the SUN Global Desktop software. If I get it right, SUN's SGD merely passes X11 forwarding over ssh, over the http protocol. The big disappointment was that Matlab's interface was sooooo slow in a way that the program was practically unusable. I tried to pinpoint the problem by fine tuning SGD but this was not the case. Then I realized that accessing Matlab from SGD is the same as accessing it using X11 forwarding over ssh.

The first clue that Matlab's way to draw the interface sucks is that you cannot run it under a standards compliant window manager like XMonad or Awesome. The proposed hack:
$ export AWT_TOOLKIT=MToolkit

just segfaults on any recent (and old, afaik) linux distro (I think this is a java problem, well java sucks also). Another clue that something is wrong with Matlab's way to draw its interface is the warning message I got when I tried to run it on OpenSUSE 11.1:
libxcb: WARNING! Program tries to unlock a connection without having acquired
a lock first, which indicates a programming error.
There will be no further warnings about this issue.

I don't really understand the above warning but what I get is that Matlab's interface developers are doing ad hoc hacks or just don't really care about Matlab's functionality in Linux.

By googling for more than three days I finally realized that the problem is a combination of java and the X11 libraries. A lot of people under different setups reported the same problem with Matlab and the common fact was that everything was fine until they upgraded their linux distro to the latest version. So I decided to install CentOS 4 in a virtual machine and try this setup as a last resort. Fortunately Matlab R2009a runs just fine in CentOS 4 and its interface is bearable under ssh -X.

UPDATE: Finally it turns out to be a libraries problem. Matlab R2009a runs also fine in CentOS 5 as long as you install the "Legacy Software Support Libraries" in the "openmotif22-2.2.3-18.i386" package.

UPDATE (issue finally solved): I found a resolution for this problem! Just put a file called "java.opts" containing the Java option "-Dsun.java2d.pmoffscreen=false" into the directory *matlabroot*/bin/*system*/

No comments:

Post a Comment