The variable in parfor cant classified

Hello.This is my code:
c_hat = zeros(n,1);
vc = zeros(m,n);
cv = zeros(m,n);
parfor j = 1:n
checks = find(H(:,j));
allIncoming = cv(checks,j);
sumAllIncoming = sum(allIncoming) + LLRs(j);
c_hat(j) = (1 - sign(sumAllIncoming))/2;
toCheck = sumAllIncoming - allIncoming;
vc(checks,j) = toCheck;
end
It is not runing because "The variable vc in a parfor cannot be classified." Without parfor it is running fine. Is it possible to run it with parfor?

Answers (1)

Matt J
Matt J on 4 Jul 2013
Edited: Matt J on 4 Jul 2013
There are rules about sliced variables and how you can index them in parfor loops. However, you can get around these rules by re-organizing vc and cv as cell arrays,
c_hat = zeros(n,1);
vc = num2cell(zeros(m,n),1);
cv = vc;
parfor j = 1:n
checks = H(:,j)~=0;
allIncoming = cv{j}(checks);
sumAllIncoming = sum(allIncoming) + LLRs(j);
c_hat(j) = (1 - sign(sumAllIncoming))/2;
toCheck = sumAllIncoming - allIncoming;
vc{j}(checks) = toCheck;
end
vc=[vc{:}]; %convert back to normal array

7 Comments

Really thanks, but i missed to say tha this parfor is inside a bigger loop.Sorry about this.The full function is:
[m n] = size(H);
c_hat = zeros(n,1);
LLRs = 2*y/sigma_2;
vc = zeros(m,n);
cv = zeros(m,n);
for iters = 1:maxiter
for j = 1:n
checks = find(H(:,j));
allIncoming = cv{j}(checks);
sumAllIncoming = sum(allIncoming) + LLRs(j);
c_hat(j) = (1 - sign(sumAllIncoming))/2;
toCheck = sumAllIncoming - allIncoming;
vc{j}(checks) = toCheck;
end
if( sum(mod(H*c_hat,2)) == 0 )
return;
end
for j = 1:m
vars = find(H(j,:));
allIncoming = tanh(vc(j,vars)/2);
prodAllIncoming = prod(allIncoming);
toVar = prodAllIncoming./allIncoming;
cv(j,vars) = 2*atanh(toVar);
end
end
I cannot parfor the iters because there is return inside this loop.So i have to parfor the insider loops..I would appreciate it if you help me more.After the changes i have the problem"Conversion to cell from double is not possible.
Conversion to cell from double is not possible.
Error in decodeBP (line 57)
cv(j,vars) = 2*atanh(toVar);
Conversion to cell from double is not possible.
Perhaps you meant
cv{j}(vars)=2*atanh(toVar);
Thanks so much,but i have problem again.
[m n] = size(H);
c_hat = zeros(n,1);
LLRs = 2*y/sigma_2;
vc = num2cell(zeros(m,n),1);
cv = vc;
for iters = 1:maxiter
parfor j = 1:n
checks = find(H(:,j));
allIncoming = cv{j}(checks);
sumAllIncoming = sum(allIncoming) + LLRs(j);
c_hat(j) = (1 - sign(sumAllIncoming))/2;
toCheck = sumAllIncoming - allIncoming;
vc{j}(checks) = toCheck;
end
vc=[vc{:}];
if( sum(mod(H*c_hat,2)) == 0 )
return;
end
for j = 1:m
vars = find(H(j,:));
allIncoming = tanh(vc(j,vars)/2);
prodAllIncoming = prod(allIncoming);
toVar = prodAllIncoming./allIncoming;
cv{j}(vars) = 2*atanh(toVar);
end
end
I got the error:
Error using decodeBP>(parfor body) (line 35)
Cell contents assignment to a non-cell array object.
Error in decodeBP (line 19)
parfor j = 1:n
We cannot guess what your "line 19" is. So please explain this clearly.
@theodor,
Get rid of this
vc=[vc{:}];
and make sure you use vc and cv as a cell array everywhere, e.g.,
allIncoming = tanh( vc{j}(vars)/2 );
Really thanks for the answers. @Jan Simon line 35 was
vc{j}(checks) = toCheck;
and line 19 was
parfor j = 1:n
@Matt J I changed them but now i have the error
Index exceeds matrix dimensions.
Error in decodeBP (line 52)
allIncoming = tanh(vc{j}(vars)/2);
I take it back. Put this back
vc=[vc{:}];
but add immediately after it
vc=num2cell(vc,2);
Also, please learn to use DBSTOP to trap and investigate common errors like "Index exceeds matrix dimensions." and "Conversion to cell from double is not possible."

This question is closed.

Asked:

on 4 Jul 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!