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...
values = [30.3750000000000 30.3760000000000...
outVal = FIRMP(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);
result(I) = suma;
I used 4 threads and got this results
for : time= 13.5s
parfor: time = 5.5s
It is OK, but if I create C++ mex (matlab CODER) and run again, the result has changed
for : time = 3.1s
parfor: time = 4.3s
why is the 'parfor' in C++ mex slower than 'for'?