具有大量迭代的 MATLAB Parfor 未开始

MATLAB Parfor with high number of iterations not starting

我运行正在使用 Matlab 2014a 并尝试使用 parfor 启动脚本。但是它卡在

Starting parallel pool (parpool) using the 'local' profile ... connected to 16 workers.

我之前运行一个测试脚本,它工作正常。不同之处在于,测试脚本有 4 次 parfor 迭代和 2 个 5x12x3x4 大小的数组,它们填充在 parfor 循环中,而主脚本有 100 次迭代和 2 个 31x12x3x100 大小的数组。 任何关于如何制作它的想法 运行? 谢谢!

编辑:这里是我的代码的简化版本来说明问题,请注意这个版本,我不包括计算实际工作。包含计算是不可行的,因为它们涉及其他 Matlab 和 Python 脚本。另外,当我说卡住时,我的意思是我没有从 disp(output) 行获得任何输出。

close all;
clear all;
clc;

disp('starting');
results_nb = zeros(31,12,3,100);
results_ht = zeros(31,12,3,100);
progress = zeros(1,100);

parfor iter = 1:100

    t = getCurrentTask(); 
    output = ['Worker:' num2str(t.ID) ', Iteration:' num2str(iter)];
    disp(output);
    j_idx=0;
    results_nb_iter=zeros(31,12,3);
    results_ht_iter=zeros(31,12,3);
    for j=[10,20,50]
        j_idx=j_idx+1;
        for i=1:31
            line_nb = zeros(1,12);
            line_ht = zeros(1,12);

            %line_nb = some calculations
            %line_ht = some calculations

            results_nb_iter(i,:,j_idx)=line_nb;
            results_ht_iter(i,:,j_idx)=line_ht;

        end
    end
    results_nb(:,:,:,iter)=results_nb_iter;  
    results_ht(:,:,:,iter)=results_ht_iter;

end

save('results')

exit

你的推论是错误的,因为你的测量是错误的。

parfor 循环内的

disp() 无法确保在 worker 到达它时准确地打印到屏幕,而是排队等候,当 worker 空闲时,它会将其发送到客户端进行打印。

要保持​​ parfor 执行的进度,您需要 parallel.pool.DataQueue

另请阅读关于同一主题的其他 Mathworks post:https://uk.mathworks.com/matlabcentral/answers/372416-how-can-i-display-the-progress-of-a-parfor-or-parfeval-loop-in-matlab-r2017a-and-newer