multithreading MATLAB 中的多线程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4495000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:11:50  来源:igfitidea点击:

Multi-threading in MATLAB

multithreadingmatlab

提问by Maddy

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!

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

回答by Jonas

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

如果你想在不同的处理器上运行一批不同的函数,你可以使用 Parallel Computing Toolbox,更具体地说,是一个parfor循环,但你需要将函数作为句柄列表传递。

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

Edit:Starting with R2015a matlabpoolfunction has been removedfrom Matlab, you need to call parpoolinstead.

编辑:从 R2015a 开始matlabpool函数已从 Matlab 中删除,您需要改为调用parpool

回答by Jason S

Try looking at the Parallel Computing Toolbox.(I'm unfortunately not too familiar with it, but that seems to be the right place.) Look at gatherand parallel for-loops.

尝试查看并行计算工具箱。(不幸的是,我对它不太熟悉,但这似乎是正确的地方。)查看gather并行 for-loops