Multi-threading in MATLAB

前端 未结 2 2021
星月不相逢
星月不相逢 2020-12-13 10:06

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(

相关标签:
2条回答
  • 2020-12-13 10:52

    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.

    0 讨论(0)
  • 2020-12-13 11:02

    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 gather and parallel for-loops.

    0 讨论(0)
提交回复
热议问题