通过使用并行工具箱创建数量有限的工作人员(ThreadPool)的任务/工作池 [英] Creating a pool of tasks/jobs with a limited amount of workers (ThreadPool) by using parallel toolbox

查看:89
本文介绍了通过使用并行工具箱创建数量有限的工作人员(ThreadPool)的任务/工作池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用并行计算工具箱来加速一组彼此不依赖的函数调用.为了提高效率,我想使用计时器函数/回调函数在我的一个函数执行完后继续执行更多的函数.我不知道提前哪个会更快,所以我不能只是将我的函数集分成几个池并设置它们并行运行.

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.

我现在有这种设置的唯一方法是我使用了str2fun的字符串单元格数组,有没有更好的方法呢?

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?

欢迎提问.

推荐答案

不需要自己编写此类代码. Matlab并行工具箱可以创建具有多个作业的计划程序. 您可以多次调用createJob,调度程序将进行拉取.

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

这篇关于通过使用并行工具箱创建数量有限的工作人员(ThreadPool)的任务/工作池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆