I am starting to work with the Parallel Computing Toolbox, and just constructed an FIR filter example to compare for and parfor
coefs = [-0.00393617608745112 -5.95945405003999e-05...] length 1x10498values = [30.3750000000000 30.3760000000000...] length 1x131000tic; outVal = FIRMP(coefs,values); %outVal = FIRMP_mex(coefs,values);
time = toc;
with function FIRMP
function [result] = FIRMP(coefs, values) coefLen = length(coefs); valLen = length(values); result = zeros(size(values)); (par)for I = 1 : valLen - coefLen; suma = 0; for J = 1 : coefLen suma = suma + coefs(J)*values(I + J); end result(I) = suma; endend
I used 4 threads and got this results
for : time= 13.5sparfor: time = 5.5s
It is OK, but if I create C++ mex (matlab CODER) and run again, the result has changed
for : time = 3.1sparfor: time = 4.3s
why is the 'parfor' in C++ mex slower than 'for'?
Best Answer