clusterHost = 'hound.sharcnet.ca';
remoteDataLocation = '/work/jemmyhu/matlab';

% Create a job scheduler / manager object:
sched = findResource('scheduler', 'type', 'generic');

% Use a local directory as the DataLocation
set(sched, 'DataLocation', 'C:\Temp');

% for R2010b
set(sched, 'ClusterMatlabRoot', '/opt/sharcnet/matlab/R2010b');
set(sched, 'DestroyJobFcn', @destroyJobFcn);
set(sched, 'GetJobStateFcn', @getJobStateFcn);

% set(sched, 'HasSharedFilesystem', true);
set(sched, 'HasSharedFilesystem', false);

set(sched, 'ClusterOsType', 'unix');

% The SubmitFcn must be a cell array that includes the two additional inputs
set(sched, 'SubmitFcn', {@distributedSubmitFcn, clusterHost, remoteDataLocation});


% Create a job object:
j = createJob(sched)

% Create a distributed task
createTask(j, @sum, 1, {[1 1]});
createTask(j, @sum, 1, {[2 2]});
createTask(j, @sum, 1, {[3 3]});
% where sum is the command name, 1 is the number of return values and 
% the rest is the argument list that is to be passed to sum().

% Submit the job - this is non blocking
submit(j)

% Retrieve the job
waitForState(j, 'finished')
r = getAllOutputArguments(j)