MatLab DCS Examples

From UABgrid Documentation
Jump to: navigation, search
Ambox important.png

This page is Deprecated
To Use MATLAB with the SLURM scheduler on Cheaha please click the link below

MATLAB with SLURM

Contents

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 is not available in R2012a. Use Job Monitor to check for state of job on the cluster)
    >> waitForState(job)   % not available on R2012a
    >> 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


MATLAB Support / Mailing List

As with any application or computer language, learning to use MATLAB to analyze data or to develop or modify MATLAB applications is an individual responsibility. There is ample application documentation available from the Mathworks website, potential outreach to colleagues who also use MATLAB, and options for consultation with Mathworks. Mathworks also host on-campus training seminars several times a year and provides many on-line learning tutorials.

Installation support for MATLAB at UAB is provided by your local IT support organization and the Docs wiki.

Mathworks Website

Your first and best option for application-specific questions on MATLAB is to refer to the on-line MATLAB documentation. The Mathworks site also provides a a support matrix and an on-line knowledge base.

UAB MATLAB Wiki

The MATLAB page on the Docs wiki is the starting point for installing MATLAB at UAB and, optionally, configuring it to use cluster computing. All users are encouraged to contribute to the MATLAB knowledge in this wiki, especially if you see areas where improvements are needed. Remember, this knowledge base is only as good as the people who contribute to it.

Contributing to the wiki is as easy as clicking the login link on the top-right of the page and signing in with your UAB BlazerID. If you are unsure about making an edit, you can make suggestions for improvement on the page's Discussion tab or discuss the proposed improvement in the MATLAB user group.

UAB MATLAB User Group

At UAB, MATLAB installation support is provided by your local IT support group. Support for application specific questions is available from peers in your research group. We realize that some people are not as familiar with MATLAB as others. For this reason, we have established a MATLAB user forum (mailing list) where users of MATLAB at UAB can help answer each others questions.

This is a network of volunteers sharing their knowledge with peers. You are encouraged to reach out to this community for questions on using MATLAB by

Archives of MATLAB user group discussions are available on-line at https://vo.uabgrid.uab.edu/sympa/arc/matlab-user. You may find your question is already answered in these archives.


UAB MATLAB announce mailing list

To receive information about UAB's MATLAB license and announcements please subscribe to the matlab-annc mailing list by

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox