Matlab parallel for loop or Matlab open pool
7 次查看(过去 30 天)
显示 更早的评论
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
It work fine but I would really like to know if there is a way to speed thing up ... Thanks a lot in advance!
0 个评论
采纳的回答
Walter Roberson
2012-7-14
编辑:Walter Roberson
2012-7-14
load() is slow. Only load what you have to.
result=zeros(25,16000);
for K = 1 : length(vector1) % length is 25
temp1 = vector1(K);
all_t1{K} = load(matfiles1(temp1).name) %load image1 from matfile1
end
for K = 1 : length(vector2) % length is 16000
temp2 = vector2(K);
all_t2{K} = load(matfiles2(temp2).name) % load image2 from matfile2
end
for K1 = 1 : length(vector1)
t1 = all_t1{K1};
for K2 = 1 : length(vector2)
t2 = all_t2{K2};
result(i,j) = t1 .* t2;
end
end
Note: the fact that you store the element-by-element multiplication into a single numeric entry implies that the files you load might all consist of single scalar values. If that is the case, then the storage use can be improved and the multiplication can be sped up. Store the values into row vectors and then,
result = bsxfun(@times, all_t1(:), all_t2 )
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!