parFor Worker unable to find file. Unrecognized function or variable 'parameters'

29 views (last 30 days)
Hi there I have trouble to paralize the the loop.
It is from here:
if I try to run the code below, parfor complains about the "iteration". If I set the iteration=epch, the the follwowing error occurs:
The source code ("XX".m) for the parfor-loop that is trying to execute on the worker could not be found.
Caused by:
Unrecognized function or variable 'parameters'.
Error using remoteParallelFunction (line 84)
Worker unable to find file.
Unrecognized function or variable 'parameters'.
But the "parameters" are defined-as you can see- inside the link above.
Any idea is welcome.!
Chris
start = tic;
iteration = 0;
parpool(32);
parfor epoch = 1:numEpochs
reset(mbq);
while hasdata(mbq)
iteration = iteration + 1;
dlXT = next(mbq);
dlX = dlXT(1,:);
dlT = dlXT(2,:);
% Evaluate the model gradients and loss using dlfeval and the
% modelGradients function.
[gradients,loss] = dlfeval(accfun,parameters,dlX,dlT,dlX0,dlT0,dlU0);
% Update learning rate.
learningRate = initialLearnRate / (1+decayRate*iteration);
% Update the network parameters using the adamupdate function.
[parameters,averageGrad,averageSqGrad] = adamupdate(parameters,gradients,averageGrad, ...
averageSqGrad,iteration,learningRate);
end
% Plot training progress.
loss = double(gather(extractdata(loss)));
addpoints(lineLoss,iteration, loss);
D = duration(0,0,toc(start),'Format','hh:mm:ss');
title("Epoch: " + epoch + ", Elapsed: " + string(D) + ", Loss: " + loss)
drawnow
end
  2 Comments
Edric Ellis
Edric Ellis on 13 Aug 2021
It doesn't look like you've defined parameters inside the parfor loop? The first reference I see is in the dlfeval call. To be a legal parfor loop, you'd need to define parameters just after the start of each iteration of parfor.
I suspect however that this loop isn't parallelisable in this way. Surely each iteration of the loop depends on the previous iteration (via the parameters variable).
CSCh
CSCh on 13 Aug 2021
Thank you for your comment Edric,
If this loop is not parallelisable, are there any workarounds available?

Sign in to comment.

Answers (1)

Raymond Norris
Raymond Norris on 13 Aug 2021
As Edric mentioned, this is/may not parallizable. But if it were, you'd need to make modifications to the for-loop. You've included the updating of the figure within the parfor, which won't work as you're expecting (the pool of workers don't have access to your client MATLAB displaying the plot). There are ways around this, but won't address the fundemental issue of whether the loop can be parallelized.
I would suggest circling back to the Training Options section of the example, where it describes using GPUs to help train the model. I suspect this is where you find you best option to speed up the code.
  12 Comments
Walter Roberson
Walter Roberson on 25 Aug 2021
Could you remind us if your computation is single precision or double precision?
512 cores looks to be one of:
  • GeForce GTX 580 (late 2010) (GF110 -- Fermi based), which does double precision at 1/8 of the single precision rate, about 197 gigaflops
  • GeForce GTX 750 (early 2014) (GM107 -- Maxwell based), which does double precision at 1/32 of the single precision rate, about 34 gigaflops
You may have noticed that the older card does double precision about 6 times faster than the newer card. When you are doing double-precision work you need to pay a lot of attention to the specifications for the individual model !!

Sign in to comment.

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!