Reputation: 1076
I would like to use the parallel computing toolbox to speed up a set of function calls that do not depend on each other. To make this more efficient I would like to use timer functions/callback functions to continually execute more of the functions after one of my function finishes executing. I don't know ahead of time which ones will be faster, so I can't just divide my set of functions into a few pools and set them up going in parallel.
In other words, I would like a few parallel executions to keep pulling from a pool of functions.
The only way I have this set up now I have a cell array of strings that I use str2fun
on, is there a better way to do this?
Questions are welcome.
Upvotes: 3
Views: 1024
Reputation: 20915
There is no need to write such code by yourself. The Matlab parallel toolbox has the ability to create a scheduler with multiple jobs.
You can call createJob
multiple times, and the scheduler will do the pulling.
foos = [@foo1,@foo2,@foo3,@foo4]
for i=1:numel(foos)
obj = createJob();
createTask(obj, foos(i), 1, {'your input'});
submit(obj);
end
Upvotes: 5
Reputation: 16065
Why not doing something simpler like:
matlabpool 3
parfor t=1:3
if t==1
a1=f1();
end
if t==2
a2=f2();
end
if t==3
a3=f3();
end
end
Upvotes: 0