UC San Diego SearchMenu

Usage Example for MATLAB on a Desktop Submitting a Job to the TSCC MDCS

First create a parallel profile in MATLAB for TSCC. To do this:

  1. From the HOME tab in MATLAB select "Manage Cluster Profiles" from the "Parallel" pull down menu
  2. From the "Add" pulldown menu select "Custom"
  3. From the "Custom" pulldown menu select "Generic" ("GenericProfile1" will appear in the "Cluster Profile" list) 
  4. Select "GenericProfile1", and clicking with the right mouse button, select "Set as Default"
    MATLAB Profile Manager image
  5. Using the scroll bar, scroll down to "SUBMIT FUNCTIONS". In the field to the right of "Function called when submitting independent jobs", enter "independentSubmitFcn"
  6. In the field to the right of "Function called when submitting communicating jobs", enter "communicatingSubmitFcn"
    MATLAB Profile Manager image
  7. Using the scroll bar, scroll down to "CLUSTER ENVIRONMENT". Change "Use Default" to "unix" from the pull down menu
  8. Change the value "Job storage location is accessible from client and cluster nodes" from "Use default" to "false"
    MATLAB Profile Manager image

Next, download the file archive which contains these files:

communicatingJobWrapper.sh
communicatingSubmitFcn.m
createSubmitScript.m
deleteJobFcn.m
extractJobId.m
getJobStateFcn.m
getRemoteConnection.m
getSubmitString.m
independentJobWrapper.sh
independentSubmitFcn.m

Copy these files to the toolbox/local directory of your local MATLAB installation. These are modified versions of the MATLAB files that come with the MATLAB release. These files allow you to specify several job parameters.

Using these modified files, you may also set:

  • number of processors per node
  • account name
  • queue name
  • wall clock time

Other parameters that need to be set include

  • name of the remote cluster (tscc.sdsc.edu)
  • directory where temporary data will be stored on TSCC
  • directory where data will be stored on the desktop
  • path to the desktop ssh private key file
  • path to MATLAB on TSCC

Here is an example MATLAB function that creates a cluster object:

function [ cluster ] = getCluster(username,account,clusterHost,ppn,queue,time,DataLocation,
               RemoteDataLocation,keyfile,ClusterMatlabRoot)
     cluster = parcluster('GenericProfile1');
     set(cluster,'HasSharedFilesystem',false);
     set(cluster,'JobStorageLocation',DataLocation);
     set(cluster,'OperatingSystem','unix');
     set(cluster,'ClusterMatlabRoot',ClusterMatlabRoot);
     set(cluster,'IndependentSubmitFcn',{@independentSubmitFcn,clusterHost,
               RemoteDataLocation,account,username,keyfile,time,queue});
    set(cluster,'CommunicatingSubmitFcn',{@communicatingSubmitFcn,clusterHost,
               RemoteDataLocation,account,username,keyfile,time,queue,ppn});
     set(cluster,'GetJobStateFcn',{@getJobStateFcn,username,keyfile});
     set(cluster,'DeleteJobFcn',{@deleteJobFcn,username,keyfile});

The following test function takes as its arguments all the parameters listed above, and returns a MATLAB cluster object that will be used to create an MDCS job.

Here is a MATLAB function used in a simple MDCS example job:

       processors=32
       clusterHost='tscc.sdsc.edu'
       ppn=16
       username='jpg'
       account='use300'
       queue='hotel'
       time='01:00:00'
       DataLocation='/Users/jpg/Documents/MATLAB/data'
       RemoteDataLocation='/home/jpg/matlab/data'
       keyfile='/Users/jpg/.ssh/id_rsa'
       matlabRoot='/opt/matlab/2013b'
       cluster = getCluster(username,account,clusterHost,ppn,queue,time,DataLocation,
                 RemoteDataLocation,keyfile,matlabRoot);
       j = createCommunicatingJob(cluster);
       j.AttachedFiles={'testparfor2.m'};
       set(j,'NumWorkersRange',[1 processors]);
       set(j,'Name','Test');
       t = createTask(j,@testparfor2,1,{processors});
       submit(j);
       wait(j);
       pause(30);
       o=j.fetchOutputs;
       o{:}

In this example, a cluster object (cluster) is returned by getCluster(), which is passed to createCommunicatingJob(), which returns a job object. The files that are required on the cluster are defined, as well as the number of processors (32 in this case). A task is created that will call the function testparfor2() which has one output argument and one input argument with the value 32. The job is then submitted, and the output is stored in a MATLAB cell array.

Here is the function that is submitted to run:

    function a = testparfor2(N)
          a = zeros(N,1);
          parfor(i=1:N)
          feature getpid
          a(i) = ans
     end

In this simple example, an array of dimension N is initialized with zeros, and the process ID is written to each array element. Since in this case we have passed the number 32 to N and we have asked for 32 processors, we might expect to get 32 different processes to run the tasks.

However, when we examine our output array:

ans =

       27892
       24571
       27880
       24572
       24576
       24573
       27893
       24578
       24587
       27877
       24583
       24586
       27884
       27876
       27881
       24585
       24581
       24582
       27889
       27887
       27879
       24574
       27883
       27890
       24588
       27886
       24580
       24575
       27888
       27891
       27878
       27880

we can see that only 31 worker processes were used to perform the job. Two of the loop passes were performed by the same process (27880). The reason is that MATLAB uses one worker to run the serial code, allocating the remaining workers to perform the parallel functions. Since this only leaves 31 available workers, one of them must handle two loop iterations.

MATLAB Tutorial