From: Shalmali Bodas on
I have a 4D data set D[nX, nY, nZ, nT]. I need to fit a curve to the elements of this data. Currently this is how I do it -
for x = 1: nX
for y = 1:nY
for z = 1:nZ
T(:) = D(x, y, z, :);
if T(0) ~= 0
[cval err] = fit(time, T, fitFunction, options, 'problem', delT);
cval = coeffvalues(cf);
A1(x,y,z)= cval(1);
K1(x,y,z) = cval(2);
end
end
end
end

nX = 128, nY = 64, nZ = 64, nT = 32.
On my dual core machine, it used to to take about 27 hrs. (!!)
I have Matlab 2007a which had a 'preference' where I checked 'Use multithreading' and the run time went down to about 15 hrs. (Hours!!)
We now have Matlab 2010a on a Xeon quad core. It allows hyper threading and thus can have eight cores. It also has a nVidia Tesla card in it. I want to use all this computing power and get my analysis done in minutes (if not seconds).

I plan to take small steps towards the goal. First I tried to use the 'parfor' on the loop indexed with z. mlint did not like the way D is accessed. Hence I changed that part so that the code looks like -
for x = 1: nX
for y = 1:nY
ZT = D(x, y, :, :);
ZT = reshape(ZT, nZ, nT);
parfor z = 1:nZ
T(:) = ZT(z, :);
if T(0) ~= 0
[cval err] = fit(time, T, fitFunction, options, 'problem', delT);
cval = coeffvalues(cf);
A1(x,y,z)= cval(1);
K1(x,y,z) = cval(2);
end
end
end
end

Now, I keep getting an error saying - Unknown calling sequence to FIT at line 1198.
If I remove the parfor, it works.

What am I doing wrong?