필터 지우기
필터 지우기

colon operation (:) causes parfor to fail on cell array

조회 수: 1 (최근 30일)
Marshall
Marshall 2013년 3월 28일
댓글: Sergio Santos 2015년 2월 16일
The following code causes Matlab to throw subscript assignment error:
s=cell(1,20);
parfor i = 1:20
    s{:,i}=1;
end
However, when the colon operator is replaced with a 1, there is no error:
s=cell(1,20);
parfor i = 1:20
    s{1,i}=1;
end
My guess is this involves a slicing issue somehow. Any insights?
  댓글 수: 1
Sergio Santos
Sergio Santos 2015년 2월 16일
There is a solution to this. Reshaping whatever you want to send to parfor and turning it into a single column or raw vector. Also make a vector to store the length of each vector you reshape. Then when the operation is finished reshape back into matrix form. Shaping and reshaping is very fast and can be fastly done by a single worker, i.e. no need parallel computing.

댓글을 달려면 로그인하십시오.

채택된 답변

Marshall
Marshall 2013년 4월 12일
편집: Marshall 2013년 4월 12일
Here's the response I got the other day from Mathworks:
--------------------------------------------------------------------------
Hello
First of all I would like to apologize for the delay in my response. It has been very busy over here.
I was researching on this issue and in order to find a valid explanation for this I collaborated with the experts.
In the following code,
s=cell(1,20);
parfor i = 1:20
s{:,i}=1;
end
The way PARFOR interprets this is that it is expecting a vector of size 20 on the RHS which could be stored in the vector “s”. Hence, you get a “dimension mismatch” error.
However,
s=cell(1,20);
parfor i = 1:20
s{1,i}=1;
end
This executes fine because only a scalar value is expected in the RHS for “s{1,i}”.
This is a bug in the execution of PARFOR about how it interprets the various variables and its assignments. I would like to thank you for bringing this to our notice. I have captured this in a bug report and forwarded it to the developers for future consideration.
If you have any other questions regarding MATLAB, please feel free to reply to this email and I would be happy to assist you.
Thanks Anuj
--------------------------------------------------------------------------
I'm a bit skeptical of their reason; I don't know why parfor would expect a vector of size 20, when the dimension along the colon operator is only length 1. Unless that is the bug that they're fixing.

추가 답변 (2개)

Cedric
Cedric 2013년 3월 28일
편집: Cedric 2013년 3월 28일
It has a priori nothing to do with PARFOR; the expression involving the colon on the left hand side is a comma separated list (CSL), so you cannot have the scalar 1 on the right hand side. Try it with a simple FOR loop and there will be no difference.
I don't know exactly what you want to do with that, but I guess that it is something like
s(:,i) = {1} ;
  댓글 수: 7
Cedric
Cedric 2013년 3월 29일
Thank you for the update! I will think about it a bit more about it and perform a few tests on my side.
Marshall
Marshall 2013년 3월 29일
No problem. I believe the issue is semaphore related, since I get an error from parfor's consume value. Check this out:
function tmp
y=zeros(25,25);
parfor i = 1:25
fprintf('%g ',i);
y(i,:)=1;
end
(note that in a parallel loop, each worker is assigned its own stdout line, so each line of output comes from a single worker)
The result is this:
>> tmp
14 13 12 11
10 9 8 7 6
5 4 3 2 1
17 16 15
Error using tmp>(parfor consume) (line 1)
Subscripted assignment dimension mismatch.
Error in tmp (line 14)
parfor i = 1:25
Caused by:
Subscripted assignment dimension mismatch.
So...it's not a syntax or logical issue, it's an issue where the one of the workers is running into a problem beginning one of the iterations. The Mathworks application support engineer is looking into it.

댓글을 달려면 로그인하십시오.


Ben
Ben 2013년 4월 12일
please tell us they working on a patch. i've come across this bug too now in 2013a

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by