parfor fails with loop indices being uint64

1 次查看(过去 30 天)
Documentation on parfor says that the loop indices can be of type uint64.
But with the following code, parfor fails. Either setting N to uint64(100) or changing the type of N to double/uint32 makes the code work. Is this a bug?
N = uint64(50);
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end
% fail
N = uint64(100);
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end
% work
N = uint32(50);
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end
% work
N = 50;
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end
% work
The error report is
An UndefinedFunction error was thrown on the workers for 'A'.
This might be because the file containing 'A' is not
accessible on the workers. Use addAttachedFiles(pool, files)
to specify the required files to be attached. See the
documentation for 'parallel.Pool/addAttachedFiles' for more
details.
Caused by:
Undefined function or variable 'A'.
  4 个评论
Jan
Jan 2017-10-27
The question is still not clear: What does "fail" and "work" exactly? Please post again:
N = uint64(50);
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end
% Does it work?
N = 50;
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end
% Does it work?
Which Matlab version are you using?
Rik
Rik 2017-10-27
On R2017b (on 64 bit W10), the code below results in the mentioned error as well.
N = uint64(100);
A = zeros(3,N);
parfor r = 1:N
A(:,r) = rand(3,1);
end

请先登录,再进行评论。

采纳的回答

Edric Ellis
Edric Ellis 2017-10-30
This is indeed a bug in the implementation of parfor. Thanks for reporting this, we'll endeavour to fix this in a future release of MATLAB / Parallel Computing Toolbox. For now, I'm afraid the only workaround is to avoid using uint64 loop bounds for parfor.
  1 个评论
Eli4ph
Eli4ph 2018-1-23
Could you explain a bit more? Does this bug affect other functions provided by MATLAB, in particular integer arithmetic (plus/minus and multiplication/division/remainder). Due to this bug, I feel unsafe about doing things with integral type. However now I have to pass data from MATLAB to C++ MEX file. Sorry to bother you again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by