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','~/matlab77');
% Yes, we have a shared filesystem
set(sched,'HasSharedFileSystem',true);
% Tell worker nodes where to find matlab
set(sched,'ClusterMatlabRoot','/appl/matlabr2008b');
%% Set submitfunction
% Either submitFunc, submitFuncHimem or submitFunHimem2for the highmemory queues 
set(sched,'ParallelSubmitFcn',@sgeParallelSubmitFcn);
%set(sched,'ParallelSubmitFcn',@sgeParallelSubmitFcnHimem);
%set(sched,'ParallelSubmitFcn',@sgeParallelSubmitFcnHimem2);
%set(sched,'ParallelSubmitFcn',@sgeParallelSubmitFcnHimemlong);
%set(sched,'ParallelSubmitFcn',@sgeParallelSubmitFcnLong);
%set(sched,'ParallelSubmitFcn',@sgeParallelSubmitFcnFast);

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

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)
