TULIP Resources‎ > ‎

Matlab Distributed Computing Project on a Computer Cluster (I: Basic)

Summary

What you will learn: (for Windows user)
  • How to run Matlab Distributed computing
  • How to run Matlab Parallel computing
What you need before reading this tutorial

Setup your Matlab to work with VPAC (for Windows Users)

Step1: setup to connect to our account using public key and private keyusing Putty key generator:
  

   Step2: download PSCP and Plink  and save in any folder for example I save it in C:\WINDOWS
            then you have to go in to Environment tab of the System Control Panel.and set the path to C:\WINDOWS  like below
.

      Step3: open putty software and enter the detail as below. then save this session

after doing all of this save this session and try log in your account by this putty software, you will see that you dont have to enter username and password and it automatically go in to command window.
   
       Step4: run pageant software, and do as below

           Step5:    you will need to establish a c:\matlab directory where you can put your data and results, as scp does not work with spaces in path names in this instance. The entire MATLAB Windows toolbox needs to be copied into this directory. e.g.,
cp c:\$matlabroot\toolbox\distcomp\examples\integration\pbs\nonshared\windows\ c:\matlab\windows

Setting the MATLAB path correctly

Before using MATLAB PCT you will need to configure the MATLAB path to include the correct set of submit functions for your system. To do this go to the File menu and select the "Set Path" option. Select the "Add Folder" option and then add one of the two options below depending on whether you use Linux or Windows. $MATLAB represents the location where MATLAB is installed on your computer, you will need to navigate to the directory below by hand.

Linux: $MATLAB/toolbox/distcomp/examples/integration/pbs/nonshared/unix

Again in MS-Windows the task is a little trickier. First the existing path has to be removed i.e.,

$MATLAB\toolbox\distcomp\examples\integration\pbs\nonshared\windows

Then the new path (see above) has to be added.

c:\matlab\windows

Run simple job using Matlab Distributed Computing 

    The concept for this process is that you will write some simple code to send to Vpac server and it will run the code there then return back to you the result. You can copy the following code put in an .m file and run it your matlab directly (make sure that all the above sections is setup correctly)

distributedcomputingsimple.m

    clusterHost = 'tango.vpac.org';    

    remoteDataLocation = '/home/xxxxxxxx';    //replace this by your own location in your account space where you want to store the job data

    sched = findResource('scheduler', 'type', 'generic');

    get(sched)

    set(sched, 'DataLocation', 'C:\matlab\share');    //you can choose and folder in your computer to be share file system - matlab will create some job data in thic location.
    set(sched, 'ClusterMatlabRoot', '/usr/local/matlab/R2008a'); // change the version of matlab to your version of matlab such as R2009a, R2008b,
    set(sched, 'HasSharedFilesystem', true);
    set(sched, 'ClusterOsType', 'unix');

    set(sched, 'SubmitFcn', {@pbsNonSharedSimpleSubmitFcn, clusterHost, remoteDataLocation});

    j = createJob(sched);  //create a job to send to vpac

    get(j)

    createTask(j, @rand, 1, {3,3});  //create task for this job to generate randomly 3x3 matrix
    createTask(j, @rand, 1, {3,3}); //create task for this job to generate randomly 3x3 matrix
 
    get(j,'Tasks')

    submit(j)
    waitForState(j)
    results = getAllOutputArguments(j);
    results{1:2}

Run Parallel Job using Matlab Distributed Computing

Palalleljob.m

clusterHost = 'tango.vpac.org';    

remoteDataLocation = '/home/xxxxxxxx';    //replace this by your own location in your account space where you want to store the job data

sched = findResource('scheduler', 'type', 'generic');

get(sched)

set(sched, 'DataLocation', 'C:\matlab\share');    //you can choose and folder in your computer to be share file system - matlab will create some job data in thic location.
set(sched, 'ClusterMatlabRoot', '/usr/local/matlab/R2008a'); // change the version of matlab to your version of matlab such as R2009a, R2008b,
set(sched, 'HasSharedFilesystem', true);
set(sched, 'ClusterOsType', 'unix');

set(sched, 'ParallelSubmitFcn', {@pbsNonSharedParallelSubmitFcn, clusterHost, remoteDataLocation});  //the pbsNonSimpleParallelSubmitFcn from above example has been changed to pbsNonSharedParallelSubmitFcn

pjob = createParallelJob(sched)

//Create a parallel task using the rand function to provide 3 random numbers.

createTask(pjob, @rand, 1, {3});

set(pjob,'MinimumNumberOfWorkers',5);
set(pjob,'MaximumNumberOfWorkers',9);

submit(pjob)
 
waitForState(pjob, 'finished')
results = getAllOutputArguments(pjob)
celldisp(results);

In general, To connect to vpac server, Matlab will make use of the running Pegant to connect to the server using the public and private key, it will prepare the job and submit it to vpac server, after done, the result will be send back to our matlab program.

For further function in matlab, please read more other information, the above instruction is only show how to set up and run a small matlab code in windows on vpac server.

For more information and some more trick relating to this tutorial, please contact  Quan Vu , TULIP Lab
Comments