% Specify a cluster environment and use a local folder as the JobStorageLocation
cluster = parallel.cluster.Generic( 'JobStorageLocation', 'C:\Temp' );

% Specify file system and MATLAB Root
set(cluster, 'HasSharedFilesystem', false);
set(cluster, 'ClusterMatlabRoot', '/opt/sharcnet/matlab/R2012a');
set(cluster, 'OperatingSystem', 'unix');

% Define the additional inputs to the submit functions
clusterHost = 'hound.sharcnet.ca';
remoteJobStorageLocation = '/work/jemmyhu/matlab';

% If you want to run communicating jobs (including matlabpool), you must specify a CommunicatingSubmitFcn
set(cluster, 'CommunicatingSubmitFcn', {@communicatingSubmitFcn, clusterHost, remoteJobStorageLocation});
set(cluster, 'GetJobStateFcn', @getJobStateFcn);
set(cluster, 'DeleteJobFcn', @deleteJobFcn);

% Create a Job Scheduler object
numprocs = 4
pjob = createCommunicatingJob(cluster, 'Type','SPMD')
set(pjob,'NumWorkersRange',numprocs)

% We need to include this file on the cluster
set(pjob, 'AttachedFiles', {'paralleltestfunction.m'})

% Create and submit the task, wait for results
t = createTask(pjob, @paralleltestfunction, 1, {})

% Submit and Wait for results
submit(pjob)
wait(pjob)
results = fetchOutputs(pjob)
y = results{1}