%% Test Distributed Engine 

%% Create scheduler
sched = findResource('scheduler','type','generic');

%% Set where the job data should be stored
set(sched,'DataLocation','/path/to/my/homedir/matlab');

%% Set submitfunction
% Either submitFunc,submitFuncHimem2 or submitFuncHimem2 for the highmemory queues 
set(sched,'SubmitFcn',@submitFunc);
%set(sched,'SubmitFcn',@submitFuncFast);
%set(sched,'SubmitFcn',@submitFuncLong);
%set(sched,'SubmitFcn',@submitFuncHimemlong);
%set(sched,'SubmitFcn',@submitFuncHimem2);

% Yes, we have a shared filesystem
set(sched,'HasSharedFileSystem',true);

% Tell worker nodes where to find matlab
set(sched,'ClusterMatlabRoot','/appl/matlabr2006b');

% Avoid getting warnings. If not, one might get huge output files
warning('off');

%% Set pathdependecies for the job - ie. path to your own matlab .m-files
%  or mexfiles
%  eg. p = {'/path/to/my/homedir/matlab'};

% Create new Job 
j = createJob(sched);

for i=1:10
    a = rand; b = rand; c = rand; d = rand;
    createTask(j, @testFunc, 1, {a,b,c,d});
end

% submit the job to start calculating.
submit(j)

% and wait until job completion to get result
waitForState(j,'finished',90)

% get output from all jobs
result =  getAllOutputArguments(j)
