Behavior of parfeval when its input arguments get updated?

3 次查看(过去 30 天)
Hi all,
I'd like to make sure the new function parfeval (<http://www.mathworks.com/help/distcomp/parfeval.html>) meets my need before subscribing to Matlab 2013b. My question is as follows (see the example code below).
Suppose I have a variable x which is an argument to the function used in parfeval (in my example, it is @magic). As I am collecting results and updating x, will I (a) get the same results (the update of x doesn't affect parfeval), and (b) potentially get different results due to the update of x ? I'd really like to have (b) instead of (a).
p = gcp();
% To request multiple evaluations, use a loop.
x = 0
for idx = 1:10
f(idx) = parfeval(p,@magic,1,x); % Square size determined by idx
end
% Collect the results as they become available.
for idx = 1:10
% fetchNext blocks until next results are available.
[completedIdx,value] = fetchNext(f);
fprintf('Got result with index: %d.\n', completedIdx);
x = x + completedIdx;
end
Thanks,
Regards, Thang

采纳的回答

Edric Ellis
Edric Ellis 2013-11-14
The updates to 'x' will not be seen by the workers. When you call PARFEVAL, the input arguments and function are all packaged up together ready to be sent to a worker, and the value of 'x' is copied into that package. So, you'll get (a).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Asynchronous Parallel Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by