Code covered by the BSD License  

Highlights from
Pass task-parallel jobs with multiple tasks to a scheduler.

Pass task-parallel jobs with multiple tasks to a scheduler.

by

 

This script creates 2 jobs, each with 2 parallel tasks, to pass to a local or remote scheduler.

parjobv4.m
%% Script creates two jobs with parallel tasks
%  Specifically running this script passes task-parallel jobs 
%  with multiple tasks to the scheduler.
%
% Script requires MATLAB R2010a and the Parallel Computing Toolbox (R2010a)
% but it can use the Distributing Computing Server as well.
% (Script written by Bruce Raine (1 July 2010))

% Comment out the scheduler line you want (first is local, second is
% remote)
%
% Set up job scheduler locally
jm = findResource('scheduler','Type','local');  % using local resources first, no need for cluster
% Set up job scheduler to use remote resources on a cluster say
%jm = findResource('scheduler','Type','jobmanager',... % distributed computing server required
  %  'Name','default_jobmanager');

% Create the jobs
job1 = jm.createJob;
job2 = jm.createJob;
% make sure 'myrand.m' is coresident with 'parjobv4.m'
set(job1,'FileDependencies',{'myrand.m'});
set(job2,'FileDependencies',{'myrand.m'});
% createTask, in each case, is passed the job, function handle to myrand.m, no. of
% output args of myrand and the cell array input arg used by myrand.
job1.createTask(@myrand, 1, {{3},{3}}); % call myrand twice
job2.createTask(@myrand, 1, {{3},{3}}); % call myrand twice
% Process the jobs and thereby the tasks
job1.submit; job1.wait; disp('Finished job one');  
job2.submit; job2.wait; disp('Finished job two'); 
% Collect and display job output
results1 = job1.getAllOutputArguments;
results2 = job2.getAllOutputArguments;
% Show the 4 x 3-by-3 random matrices in nicely formatted style
fprintf('Job 1 results\n');
fprintf('%2.5f %2.5f %2.5f\n',results1{1:2});
fprintf('Job 2 results\n');
fprintf('%2.5f %2.5f %2.5f\n',results2{1:2});
% Clean up jobs
job1.destroy;
job2.destroy;
clearvars job1 job2;
%--end of parjobv4--

Contact us