1
votes

I want to run a parfor loop in MATLAB with following code

B=load('dataB.mat'); % B is a 1600*100 matrix stored as 'dataB.mat' in the local folder
simN=100;
cof=cell(1,simN);
se=cell(1,simN);
parfor s=1:simN  
    [estimates, SE]=fct(0.5,[0.1,0.8,10]',B(:,s));
    cof{s}=estimates';
    se{s}=SE';
end

However, the codes seem not work - there are no warnings, it is just running forever without any outputs - I terminate the loop and found it never entered into the function 'fct'. Any help would be appreciated on how to load external data like 'dataB.mat' in the parallel computing of MATLAB?

1
I don't see anything wrong with the code. It's possible that it's just taking a really long time. When you do parallel computing MATLAB needs to send all the necessary data to each worker. In this case B needs to be copied to every worker. If B is very large then this can cause major delays, often times taking more time than a normal for loop.jodag

1 Answers

1
votes

If I type this on my console:

rand(1600,100)

and then I save my current workspace as dataB.mat, this command:

B = load('dataB.mat');

will bring me a 1 by 1 struct containing ans field as a 1600x100 double matrix. So, since in each loop of your application you must extract a column of B before calling the function fct (the extracted column becomes the third argument of your call and it must be defined before passing it)... I'm wondering if you didn't check your B variable composition with a breakpoint before proceeding with the parfor loop.

Also, keep in mind that the first time you execute a parfor loop with a brand new Matlab instance, the Matlab engine must instantiate all the workers... and this may take very long time. Be patient and, eventually, run a second test to see if the problem persists once you are certain the workers have been instantiated.

If those aren't the causes of your issue, I suggest you to run a standard loop (for instead of parfor) and set a breakpoint into the first line of your iteration. This should help you spot the problem very quickly.