This is a reproducer for an issue with parfor in MATLAB R2023a--R2025a.
To see the issue, do the following in MATLAB R2023a--R2025a with the Parallel Computing Toolbox installed.
-
Download this directory. Suppose that you name it
test_parfor. -
Open MATLAB and change the current directory to
test_parfor. -
Run the following command in the MATLAB command window:
testIt should print
Success!at the end. -
Now, run the following command in the MATLAB command window:
profileIt should fail with an error like the following:
Analyzing and transferring files to the workers ...done. {Error using try_parfor (line 6) The source code (/home/runner/work/test_matlab/test_matlab/test_parfor/try_parfor/try_parfor.m) for the parfor-loop that is trying to execute on the worker could not be found. Error in profile (line 10) try_parfor(func); ^^^^^^^^^^^^^^^^^ Caused by: Unrecognized function or variable 'fun'. Worker unable to find file. Unrecognized function or variable 'fun'. } exit status 1
However, comparing test.m and profile.m, you will find that they are identical except for the function names. Is this expected or a bug?
I understand that the failure must depend on the fact that MATLAB has a built-in function named "profile", which is shadowed by "profile.m". Needless to say, this is bad practice, but it is not clear to me why it should lead to such a failure.
See https://github.com/zequipe/test_matlab/actions/workflows/test_parfor.yml for a GitHub Actions workflow that tests this on MATLAB R2020b+.