How to interpret the result from the matlabpool parallel processing

1 次查看(过去 30 天)
In order to understand the matlabpool parallel processing, I tried a simple example.
spmd %the statement from the Parallel computing toolbox
% Run all the statements in parallel
if labindex==1
a=2
end
if labindex==2
b=3
end
a+b
end
The expected result is supposed to be 5, but in reality there is a error:
An UndefinedFunction error was thrown on the workers for 'a'. This may be because the file containing 'a' is not accessible on the workers. Specify the required files for this parallel pool using the command: addAttachedFiles(pool, ...). See the documentation for parpool for more details. Undefined function or variable "a".
How to fix this problem

采纳的回答

Matt J
Matt J 2014-8-31
编辑:Matt J 2014-8-31
Maybe this is what you want?
spmd
if labindex==1
A=2;
end
if labindex==2
A=3;
end
end
result= A{1}+A{2}

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by