Hi
(MATLAB 9.2.0.556344 (R2017a) on Windows 10)
I am testing out the parfor function, and I run into some unexpected behaviour:
1) It seems like the order in MATLAB path changes during parfor
2) The MATLAB function strsplit seems to not work as expected in parfor
(Using parfor in the examples below is of course meaningless. But the strsplit is only a small part of a larger code which is supposed to run in parallel).
Example of #1:
I use the function library of Peter J Acklam, which had a strsplit before MATLAB introduced this function. His function takes the separator as first argument and string as second (reversed compared to MATLAB's strsplit). I am using other of his functions, so I have him added to my MATLAB path, but with lower priority than MATLAB functions. When I run this code:
a = 'hello_world';
disp('Strsplit before parfor:');
disp(strsplit(a, '_'));
disp(' ');
disp('Strsplit during parfor:');
parfor (n = 1 : 1, 4)
disp(strsplit('_', a));
end
disp(' ');
disp('Strsplit after parfor:');
disp(strsplit(a, '_'));
I get the following output
Strsplit before parfor:
'hello' 'world'
Strsplit during parfor:
** Using strsplit to Peter J. Acklam **
'hello' 'world'
Strsplit after parfor:
'hello' 'world'
Note that I added a comment inside Peter's strsplit ( Using strsplit to Peter J. Acklam **), and I am also forced to change the order of input arguments to make the code run.
Example of #2:
To avoid #1 from happening for strsplit, I can just rename Peter's strsplit to e.g. xstrsplit. But when I do that and update my code, MATLAB's strsplit seems to fail in parfor. After renaming, I run this code:
a = 'hello_world';
disp('Strsplit before parfor:');
disp(strsplit(a, '_'));
disp(' ');
disp('Strsplit during parfor:');
parfor (n = 1 : 1, 4)
disp(strsplit(a, '_'));
end
disp(' ');
disp('Strsplit after parfor:');
disp(strsplit(a, '_'));
and I get this output
Strsplit before parfor:
'hello' 'world'
Strsplit during parfor:
'hello_world'
Strsplit after parfor:
'hello' 'world'
Any input on what I am doing wrong is welcome.