MATLAB中的多线程 [英] Multi-threading in MATLAB

查看:82
本文介绍了MATLAB中的多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了MATLAB有关多线程的信息,以及如何将其内置于某些函数中.但是,我的要求是不同的. 说,我有3个函数:fun1(data1),fun2(data2),fun3(data3)....我可以在这些函数之间实现多线程吗?实际上,我有300多个函数使用大量数据.多线程可以帮助我节省很多时间.请提出命令或我可以进一步研究的内容.谢谢!

I have read MATLAB's info on multi-threading and how it is in-built in certain functions. However, my requirement is different. Say, I have 3 functions: fun1(data1), fun2(data2), fun3(data3).... Can I implement multi-threading between these functions? I actually have 300+ functions using a lot of data. Multi-threading may help me cut down a lot of the time. Please suggest a command or something which I can further research on. Thanks!

推荐答案

如果要在不同的处理器上运行一批不同的功能,则可以使用Parallel Computing Toolbox,更具体地说,是

If you want to run a batch of different functions on different processors, you can use the Parallel Computing Toolbox, more specifically, a parfor loop, but you need to pass the functions as a list of handles.

funList = {@fun1,@fun2,@fun3};
dataList = {data1,data2,data3}; %# or pass file names 

matlabpool open 

parfor i=1:length(funList)
    %# call the function
    funList{i}(dataList{i});
end

修改: 从R2015a matlabpool函数开始,已被删除 Matlab,您需要改为调用parpool.

Starting with R2015a matlabpool function has been removed from Matlab, you need to call parpool instead.

这篇关于MATLAB中的多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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