Parfor error appears all of a sudden

7 views (last 30 days)
HZ
HZ on 14 Sep 2023
Commented: HZ on 21 Sep 2023
I am a new Matlab user. My matlab code was running perfectly fine. All of a sudden, I started getting this error:
The source code (<unknown>) for the parfor-loop that is trying to execute on the worker could not be found.
Caused by:
Unrecognized function or variable 'Flag'.
Error using remoteParallelFunction (line 84)
Worker unable to find file.
Unrecognized function or variable 'Flag'.
I wasn't getting this error on the same code previously and I haven't changed anything in my code since. I don't have any file function or variable named "Flag". Your suggestions on how to resolve this would be appreciated.
Thank you
  7 Comments
Brahmadev
Brahmadev on 20 Sep 2023
Edited: Brahmadev on 21 Sep 2023
Hi, could you share the data you are using or a sample of the data that is causing this issue? You mentioned that you updated the dataset, how did you do so? Manually or programmatically? I used the following random data for your code and could not reproduce the issue.
% Sample data generation
numDataPoints = 10; % Number of data points
% Generate random data for M2vwap, M2COUPON, M2stlmnt_dt, M2MATURITY, and M2INTEREST_FREQUENCY
M2vwap = rand(numDataPoints, 1);
M2COUPON = rand(numDataPoints, 1) * 10; % Assuming coupon rates between 0 and 10%
M2stlmnt_dt = datetime('today') - caldays(randi([1, 365], numDataPoints, 1)); % Random settlement dates within the last year
M2MATURITY = M2stlmnt_dt + calyears(randi([1, 10], numDataPoints, 1)); % Maturity dates are settlement dates + random number of years (1-10)
M2INTEREST_FREQUENCY =[4,3,6,12,4,12,6,1,4,3];
% Preallocate yld array
yld = zeros(numDataPoints, 1);
% Perform the calculation in parallel
parfor i = 1:numDataPoints
yld(i) = bndyield(M2vwap(i), M2COUPON(i)/100, ...
datetime(year(M2stlmnt_dt(i)), month(M2stlmnt_dt(i)), day(M2stlmnt_dt(i))), ...
datetime(year(M2MATURITY(i)), month(M2MATURITY(i)), day(M2MATURITY(i))), ...
'Period', M2INTEREST_FREQUENCY(i), 'Basis', 5);
end
% Display the calculated yields
disp(yld);
HZ
HZ on 21 Sep 2023
The problem got solved as I forced any non-calculatable value to NaN. Basically the concern is that the function is designed to calculate bndyield when the result is positive or it gives an error. The following solves it.
parfor i = 1:size(M2, 1)
try
yld(i) = bndyield(...);
catch
yld(i) = NaN;
end
end

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!