I am trying to implement a very simple program with parfor but I get some errors. I saw nearly all of the SO questions for a possible duplication but non of them was similar to my question situation. The error I get is :
Error: The variable log_likelihood_II_with_entropy in a parfor cannot be classified.
My code is written below:
em_iterations=10;
users=5;
log_likelihood_II_with_entropy=zeros(users,em_iterations);
parfor u = 1:1:users
for current_iter=1:1:em_iterations
log_likelihood_II_with_entropy(u,current_iter)=rand();
end
end
Since
log_likelihood_II_with_entropyrelies on both theparforindex (u) and an "inside index" (current_iter) it cannot be classified. Everyparforiteration is independent from the others and they are not executed in order (that is,uwill not necessarily go from 1 tousersin order 1,2,3,4,...,users).My suggestion is to let the single
parforiteration (worker) build an entire row oflog_likelihood_II_with_entropy.In this manner every
parfortask (theparforbody itself) will preallocate and evaluate a single row, no matter what theuvalue is. And then it will replace/concatenate such value in thelog_likelihood_II_with_entropymatrix.