Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
807 views
in Technique[技术] by (71.8m points)

multithreading - Multi-threading in MATLAB

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...