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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by