MatLab DCS Examples: Difference between revisions

From Cheaha
Jump to navigation Jump to search
(added the submit scripts fro R2012a)
Line 16: Line 16:
end
end
</pre>
</pre>
<li>Next create the rParforWave.m script making sure to change the '''YOUREMAIL''' string to a working email address</li>
<li>Next create the rParforWave.m script making sure to change the '''YOUREMAIL''' string to a working email address. The following submit script is used in case of Matlab R 2011b or older. </li>
<pre>
<pre>
% Submit script for Matlab R2010b, 2011a, and 2011b
% Always set these variables
% Always set these variables
email          = 'YOUREMAIL';
email          = 'YOUREMAIL';
Line 44: Line 45:
% >> destroy(job)
% >> destroy(job)
</pre>
</pre>
<li> Matlab R2012 a uses the following submit script </li>
<pre>
% Submit script for Matlab R2012a
% Always set these variables
email          = 'YOUREMAIL';
email_opt      = 'eas';      % qsub email options
h_rt            = '00:07:00'; % hard wall time
vf              = '1G';      % Amount of memory need per task
min_cpu_slots  = 2;          % Min number of cpu slots needed for the job
max_cpu_slots  = 3;          % Max number of cpu slots needed for the job
% Configure the scheduler - Do NOT modify these
sge_options = ['-l vf=', vf, ',h_rt=', h_rt, ', ' -m ', email_opt, ' -M ', email];
SGEClusterInfo.setExtraParameter(sge_options);
cluster = findResource();
% End of scheduler configuration
% start of user specific commands
job = batch('myWave', 'matlabpool', max_cpu_slots, 'FileDependencies', {'myWave.m'});
% The following commands can be run once the job is submitted to view the results
% >> waitForState(job)
% >> load(job, 'A')
% >> plot(A)
% Once the job is complete, permanently remove its data
% >> delete(job)
</pre>
<li>Select cheaha as the parallel configuration by clicking '''Parallel -> Select Configuration -> cheaha''' in the main MATLAB window
<li>Select cheaha as the parallel configuration by clicking '''Parallel -> Select Configuration -> cheaha''' in the main MATLAB window
<li>Run the rParforWave.m code by opening the script in the MATLAB editor and clicking the green run arrow
<li>Run the rParforWave.m code by opening the script in the MATLAB editor and clicking the green run arrow

Revision as of 14:05, 12 March 2012

Examples

Additional examples and submit scripts available in the  Workshop 2011 demo  section.

Parfor

This example uses two files:

  • myWave.m - a script with a parfor loop generates a wave form
  • rParforWave.m - the submission script

The job will use 4 total slots/ MATLAB workers on the cluster (3 workers plus the master worker process).

  1. Create the myWave.m script containing this code
    parfor i=1:1024
    
      A(i) = sin(i*2*pi/1024);
    
    end
    
  2. Next create the rParforWave.m script making sure to change the YOUREMAIL string to a working email address. The following submit script is used in case of Matlab R 2011b or older.
  3. % Submit script for Matlab R2010b, 2011a, and 2011b
    % Always set these variables
    email           = 'YOUREMAIL';
    email_opt       = 'eas';      % qsub email options
    s_rt            = '00:05:00'; % soft wall time
    h_rt            = '00:07:00'; % hard wall time
    vf              = '1G';       % Amount of memory need per task
    min_cpu_slots   = 2;          % Min number of cpu slots needed for the job
    max_cpu_slots   = 3;          % Max number of cpu slots needed for the job
    
    % Configure the scheduler - Do NOT modify these
    sge_options = ['-l vf=', vf, ',h_rt=', h_rt, ',s_rt=', s_rt, ' -m ', email_opt, ' -M ', email];
    SGEClusterInfo.setExtraParameter(sge_options);
    sched = findResource();
    % End of scheduler configuration
    
    % start of user specific commands
    job = batch('myWave', 'matlabpool', max_cpu_slots, 'FileDependencies', {'myWave.m'});
    
    % The following commands can be run once the job is submitted to view the results
    % >> waitForState(job)
    % >> load(job, 'A')
    % >> plot(A)
    
    % Once the job is complete, permanently remove its data
    % >> destroy(job)
    
  4. Matlab R2012 a uses the following submit script
  5. % Submit script for Matlab R2012a
    % Always set these variables
    email           = 'YOUREMAIL';
    email_opt       = 'eas';      % qsub email options
    h_rt            = '00:07:00'; % hard wall time
    vf              = '1G';       % Amount of memory need per task
    min_cpu_slots   = 2;          % Min number of cpu slots needed for the job
    max_cpu_slots   = 3;          % Max number of cpu slots needed for the job
    
    % Configure the scheduler - Do NOT modify these
    sge_options = ['-l vf=', vf, ',h_rt=', h_rt, ', ' -m ', email_opt, ' -M ', email];
    SGEClusterInfo.setExtraParameter(sge_options);
    
    cluster = findResource();
    % End of scheduler configuration
    
    % start of user specific commands
    job = batch('myWave', 'matlabpool', max_cpu_slots, 'FileDependencies', {'myWave.m'});
    
    % The following commands can be run once the job is submitted to view the results
    % >> waitForState(job)
    % >> load(job, 'A')
    % >> plot(A)
    
    % Once the job is complete, permanently remove its data
    % >> delete(job)
    
  6. Select cheaha as the parallel configuration by clicking Parallel -> Select Configuration -> cheaha in the main MATLAB window
  7. Run the rParforWave.m code by opening the script in the MATLAB editor and clicking the green run arrow
  8. After several seconds you should see output similar to the following in the MATLAB Command Window
    • The job 294773 is the job number assigned by the Cheaha scheduler
    • The Job1 is the job name and number used by MATLAB to reference the job. In most cases, this is the number that you'll use to interact with MATLAB to load the results, clean up the job, etc...
      Your job 294773 ("Job1") has been submitted
      
  9. Now that the job has been submitted, instruct MATLAB to wait for the job to complete using waitForState. MATLAB will show as 'Busy' until the job completes, at which time the >> prompt will appear. You can verify that the job is complete by running the job.State function call.
    >> waitForState(job)
    >> job.State
    
    ans =
    
    finished
    
  10. Now that the job has completed, to view the results first use the load function to load the workspace variable A from our batch job:
    >> load(job, 'A')
    
  11. Next, display the plot
    >> plot(A)
    

    RParforWave-plot.png

  12. Once you are done with the job, make sure to run the destroy the job to clean up the space used on the cluster
    >> job.destroy
    

In the case of longer running jobs, you probably don't want to tie up your MATLAB client by using waitForState.

This will allow you to perform other tasks in MATLAB or exit entirely without having to wait for your job to complete.

MATLAB provides a function to load a previously submitted job back into the workspace, findJob.

In the example above, our MATLAB job name was Job1 and from that we can deduce that the MATLAB job number was 1. It can be loaded as follows (make sure the correct Parallel configuration is selected):

>> sched = findResource();
>> job = findJob(sched, 'ID', 1);
>> job.State

ans =

finished

It is important to clean up after the job using destroy to free up hard disk space on both your desktop and the cluster. Any output that is to be saved should be copied to another location on your Desktop prior to running destroy.

>> findJob(sched, 'ID', 1)
>> job.destroy