Creating a pool of tasks / tasks with a limited number of employees (ThreadPool) using a parallel set of tools

I would like to use the parallel computing toolbar to speed up a set of function calls that are independent of each other. To make this more efficient, I would like to use timer / callback functions to constantly perform more functions after completing one of my functions. I don’t know in advance which of them will be faster, so I can’t just split my feature set into several pools and configure them in parallel.

In other words, I would like several parallel executions to continue to extract from the pool of functions.

The only way I'm configured is now that I have an array of row cells in which I use str2fun on, is there a better way to do this?

Questions are welcome.

+3
source share
2 answers

There is no need to write such code yourself. Matlab's parallel toolkit has the ability to create a scheduler with multiple tasks . You can call createJob several times, and the scheduler will do the stretching.

  foos = [@foo1,@foo2,@foo3,@foo4] for i=1:numel(foos) obj = createJob(); createTask(obj, foos(i), 1, {'your input'}); submit(obj); end 

enter image description here

+5
source

Why not make something simpler:

 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 
0
source

Source: https://habr.com/ru/post/1396227/


All Articles