I am trying to to some computations and I would like to do it in parallel using parfor or by Opening the matlabpool.. as the current implementations is too slow:
result=zeros(25,16000);
for i = 1:length(vector1) % length is 25
for j = 1:length(vector2) % length is 16000
temp1 = vector1(i);
temp2 = vector2(j);
t1 = load(matfiles1(temp1).name) %load image1 from matfile1
t2 = load(matfiles2(temp2).name) % load image2 from matfile2
result(i,j)=t1.*t2
end
end
its works fine but I would really like to know if there is a way to speed thing up …
Thanks a lot in advance!
Using a
parforloop and opening amatlabpoolgo together. Opening thematlabpoolprovides your MATLAB session with dedicated workers with which it can run the body of yourparforloop. So, you could change your code to something like this:Before running your code in parallel, I would definitely recommend using the MATLAB profiler to ensure you understand where the time is being spent running your code. (I’m a little surprised that hoisting the
loadintot1into the outer loop has no effect – the profiler presumably should therefore show that theloadcalls take very little time compared to the rest of your algorithm).