Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use Matlab with Xgrid Apps
It is possible to use MATLAB with Xgrid. Until recently, every time I tried this, MATLAB either failed to start or would immediately die with a "bus error" after starting. However, I discovered through trial and error that Matlab simply requires that the HOME environment variable exists.

So the way to use MATLAB is to use a shell script that will set the environment variable correctly, then invoke MATLAB with a numerical argument. Read the rest of the hint for an example...

  1. Create a shell script called
    # For some reason, MATLAB dies if you don't have
    # HOME set in environment
    export HOME=/home/username
    /Applications/MATLAB7/bin/matlab -nojvm -nodisplay -r $X ;
    As you see, you have to make sure you call MATLAB with the nojvm argument, or else it will complain about not being the console user. The -r argument lets you specify a function to run. In this example, the shell variable X is used to pass a different input argument, based on what Xfeed supplies from the range agument.

  2. Create a MATLAB function called foo (foo.m):
    function foo(in)
        disp(['in was: ',num2str(in)])  
        % Now do something
        A = [(in-1)*10+1:(in*10)];
        disp('Something went wrong')
      % It is critical that your task ends with "exit"
  3. Put these in a directory called matlab_test

  4. Create a directory to store results called matlab_out

  5. Launch Xgrid, then choose the Xfeed plugin. Give it the following arguments (final settings screenshot):
    • Command: /bin/sh
    • Argument 1: Literal
    • Argument 2: Range From: 1 to: 16 by: 1
    • Source: /path/to/matlab_test
    • Destination: /path/to/matlab_out
When you hit "Submit Job," you should get the results in your matlab_out directory. For example, sh_matlabfoo.sh_5.txt:
                              < M A T L A B >
                  Copyright 1984-2004 The MathWorks, Inc.
                         Version (R14)
                                May 06, 2004

  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit
in was: 5
    41    42    43    44    45    46    47    48    49    50
[robg adds: I haven't tested this one.]
  • Currently 2.60 / 5
  You rated: 3 / 5 (5 votes cast)

Use Matlab with Xgrid | 3 comments | Create New Account
Click here to return to the 'Use Matlab with Xgrid' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Matlab with Xgrid
Authored by: tanvach on Nov 26, '04 02:36:41PM

Wow... I'm using matlab for my project to do LOTs of fft & ifft in a loop, this might really make things much faster. What kind of speed up did you manage to get? I would imaging Xgrid will have some overhead associated with splitting the work load on multiple machines.

[ Reply to This | # ]
Use Matlab with Xgrid
Authored by: ianfasel on Nov 27, '04 04:46:56AM
This hint isn't really for doing any fine-grained parallelism, its more for "embarassingly parallel" tasks, and you pretty much have to split up the work by hand. In the example I gave, matlab will launch and immediately run foo.m on each machine, and the input argument will be a number unique to that instance of matlab which you can use as an index into "work chunks". Then you would write code in foo.m to decide which chunk of data to work on based on that index. In this kind of situation speed scales linearly with processors, minus whatever overhead there is passing around your data.

I have done some more fine-grained parallelism with matlab based on the "MatlabMPI" toolbox. This doesn't use Xgrid or have any sense of load balancing however. I wrote my own wrappers around this to do some ad hoc load balancing, but this is basically in-house research code, not ready for prime time yet.

In the meantime, The MathWorks just released a new toolbox for distributed computing. I haven't tried it yet, but it looks quite handy.


[ Reply to This | # ]

Use Matlab with Xgrid
Authored by: Anonymous on Nov 27, '04 10:16:23PM

There is a free webinar on December 9, 2004 for the Distributed Computing toolbox:

[ Reply to This | # ]