[ GJL | Maths | Maths Staff | Getting to HW]

To use the matlab compiler in the simplest way possible:

FIRST :
You need to set your LD_LIBRARY_PATH to pick up the library.
Type at a unix terminal you are going to use : EITHET Or add to your .cshrc file or similar.

For bash use export LD_LIBRARY_PATH= ...


Example 1:

  • Convert the matlab script: hello.m given below

    %
    % Boring loop
    %
    for iter = 1 : 10
    fprintf('Hello, world again %d \n', iter);
    end

    To a function : hello.m as below

    function hello
    %
    % Boring loop
    %
    for iter = 1 : 10
    fprintf('Hello, world again %d \n', iter);
    end

  • To Compile type either in a unix terminal or matlab console : mcc -m hello.m
    This produces files : hello, hello_main.c, hello_mcc_component_data.c, hello.prj
    and the exececutable is hello.
  • To Run : in unix terminal type : hello

    Example 2:

    Now an example where we read in data from a file (MT.dat) so we can easily change parameters.
    We also write out data to another file to save the results (XX.dat)

  • Make the input file MT.dat (values of M and T)
  • Compile the matlab sde.m : mcc -m sde
    (typed either at a terminal or matlab console.)

    function sde
    randn('state',1000);
    load MT.dat % load in a value for M and T
    M=MT(1);
    T=MT(2);
    Dt=0.01;
    K=T/Dt;
    Db=zeros(K,M);
    beta=zeros(K,M);
    XX=zeros(K,M);
    sdt=sqrt(Dt);
    lambda=-1;
    mu=1;
    X=randn(1,5);
    XX(1,:)=X;
    for k=1:K
    Db(k,:)=sdt*randn(1,M);
    X = X + Dt*lambda*X + mu*X.*Db(k,:);
    XX(k+1,:)=X;
    end
    time=(0:Dt:T)';
    save -ascii XX.dat XX % save the output to use ;later
    % For me the plot does not work
    %plot(time,mean(XX,2),'b+-',time,XX);

  • To Run : in unix terminal type: sde
  • To run in a friendly way : nice sde

    This will read in MT.dat and write the computed data to ascii file XX.dat


    Example 3:

    Now an example with functions

  • sde2.m uses functions fx.m and gx.m
    (it also reads in from the file MT.dat)
  • Compile the matlab and start the list with the 'main' routine : mcc -m sde2 fx gx
  • To Run : in unix terminal type : sde2
  • To run in a friendly way and in the background : nice sde2 &
  • It will output the ascii file XX.dat.

    Notes :

    Official Matlab Docs

    1) You might want to put the output from the screen into a file.
    EG in unix terminal type : nice sde2 > screen.txt &
    (I think you can then log out and it will carry running and you don;t use anything ...)

    2) For me figures do not seem to work on lxgabriel ... (it does on another)

    3) There are some commands that are supposed not to work (eg cputime)

    4) Compiling using mcc in the unix terminal keeps the matlab license for 30 mins.

    5) Compiling using mcc in matlab keeps the matlab license until you quit. (So compile and then quit).

    6) You might want to run the job in the background and 'niced' -- see examples 2 and 3 above


    To start a job and then logout

    eg for remote log in

    ssh into workstation

    start screen

    start your job as above

    hit Ctrl-a d

    logout of ssh


    Email if any comments, corrections or additions.