Problem with parfor loop due to some variable that cannot be classified.
3 次查看(过去 30 天)
显示 更早的评论
I am unable to specify a parfor loop that works due to some variable that matlab cannot classify
I tried to implement the following function
function somefunction(N,NWorkers)
counts=zeros(1,actualNworkers);
P=myprogress(N,actualNworkers);
parfor (isim=1:N,NWorkers)
local_labindex=1;
if NWorkers
local_labindex=labindex;
end
counts(local_labindex)=counts(local_labindex)+1;
send(P,[local_labindex,counts(local_labindex)])
end
end
But Matlab complains that "The PARFOR loop cannot run due to the way counts is used"
When this failed, I tried to use a cell array instead of a vector. But that didn't work either. Finally I tried to implement a nested function as shown below but it still does not work
function somefunction(N,NWorkers)
counts=zeros(1,actualNworkers);
P=myprogress(N,actualNworkers);
parfor (isim=1:N,NWorkers)
local_labindex=1;
if NWorkers
local_labindex=labindex;
end
o=increment(local_labindex);
send(P,[local_labindex,o])
end
function o=increment(index)
counts(index)=counts(index)+1;
o=counts(index);
end
end
But this time the error message is : "The nested INCREMENT cannot be called from within a PARFOR loop"
Is there any workaround this problem?
7 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Distributed Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!