clear
warning('off')

%% Create scheduler
sched = findResource('scheduler','type','generic');
% sched = findResource('scheduler', 'type', 'generic');
% set(sched,'configuration','sge');
%% Set where the job data should be stored
set(sched,'DataLocation','~/matlab81');
% Yes, we have a shared filesystem
set(sched,'HasSharedFileSystem',true);
% Tell worker nodes where to find matlab
set(sched,'ClusterMatlabRoot','/appl/matlabr2013a');
%% Set submitfunction
% Either submitFunc, submitFuncHimem or submitFunHimem2for the highmemory queues 
set(sched,'ParallelSubmitFcn',@parallelSubmitFcn);
%set(sched,'ParallelSubmitFcn',@parallelSubmitFcnHimem);
%set(sched,'ParallelSubmitFcn',@parallelSubmitFcnHimem2);
%set(sched,'ParallelSubmitFcn',@parallelSubmitFcnHimemlong);
%set(sched,'ParallelSubmitFcn',@parallelSubmitFcnLong);
%set(sched,'ParallelSubmitFcn',@parallelSubmitFcnFast);

% Create the Job 
pjob = createParallelJob(sched);
p = {'~/matlab81'};

set(pjob, 'FileDependencies', {'colsum.m'});
% set pathdependecies 

set(pjob, 'MaximumNumberOfWorkers', 8)
set(pjob, 'MinimumNumberOfWorkers', 8)
t = createTask(pjob, @colsum, 1, {rand(8)})
submit(pjob)

waitForState(pjob,'finished')
result =  getAllOutputArguments(pjob)
