Behavior of parfeval when its input arguments get updated?

3 views (last 30 days)
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

Accepted Answer

Edric Ellis
Edric Ellis on 14 Nov 2013
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).

More Answers (0)

Categories

Find more on Asynchronous Parallel Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!