MatLab DCS Examples: Difference between revisions
(added the submit scripts fro R2012a) |
(waitForState not available on R2012a) |
||
Line 84: | Line 84: | ||
Your job 294773 ("Job1") has been submitted | Your job 294773 ("Job1") has been submitted | ||
</pre></ul> | </pre></ul> | ||
<li>Now that the job has been submitted, instruct MATLAB to wait for the job to complete using [http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/waitforstate.html 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. | <li>Now that the job has been submitted, instruct MATLAB to wait for the job to complete using [http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/waitforstate.html 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 fro state of job on the cluster) | ||
<pre> | <pre> | ||
>> waitForState(job) | >> waitForState(job) % not available on R2012a | ||
>> job.State | >> job.State | ||
Revision as of 14:08, 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).
- Create the myWave.m script containing this code
parfor i=1:1024 A(i) = sin(i*2*pi/1024); end
- 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.
- Matlab R2012 a uses the following submit script
- Select cheaha as the parallel configuration by clicking Parallel -> Select Configuration -> cheaha in the main MATLAB window
- Run the rParforWave.m code by opening the script in the MATLAB editor and clicking the green run arrow
- 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
- 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 fro state of job on the cluster)
>> waitForState(job) % not available on R2012a >> job.State ans = finished
- 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')
- Next, display the plot
>> plot(A)
- 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
% 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)
% 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)
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