parfor循环中工作的动态分配

parfor循环中工作的动态分配

本文介绍了Matlab并行计算工具箱,parfor循环中工作的动态分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 matlab 中使用长时间运行的 parfor 循环.

I'm working with a long running parfor loop in matlab.

parfor iter=1:1000
   chunk_of_work(iter);
end

每次运行通常有大约 2-3 个计时异常值.也就是说,每执行 1000 块工作,就有 2-3 块花费的时间大约是其他工作的 100 倍.随着循环接近完成,评估异常值的工作人员继续运行,而其余工作人员没有计算负载.

There are generally about 2-3 timing outliers per run. That is to say for every 1000 chunks of work performed there are 2-3 that take about 100 times longer than the rest. As the loop nears completion, the workers that evaluated the outliers continue to run while the rest of the workers have no computational load.

这与 parfor 循环静态分配工作是一致的.这与并行计算工具箱的文档形成对比 在这里找到:

This is consistent with the parfor loop distributing work statically. This is in contrast with the documentation for the parallel computing toolbox found here:

工作分配是动态的.而不是被分配一个固定的迭代范围,只有在他们完成了当前迭代的处理,结果是甚至工作负荷分配."

对正在发生的事情有什么想法吗?

Any ideas about what's going on?

推荐答案

我认为您引用的文档对静态工作分配进行了很好的描述:每个工人被分配了一个固定的迭代范围".对于 4 个工人,这意味着第一个被分配 iter 1:250,第二个 iter 251:500,...或第一个分配的 1:4:100, 2:4:1000 以此类推.

I think the doc you quote has a pretty good description what is considered a static allocation of work: each worker "being allocated a fixed iteration range". For 4 workers, this would mean the first being assigned iter 1:250, the second iter 251:500,... or the 1:4:100 for the first, 2:4:1000 for the second and so on.

您没有准确说出您观察到的内容,但您所描述的内容与动态工作负载分布非常一致:首先,四个(示例)工作人员各自处理一个 iter,第一个是完成了第五个工作,下一个完成的工作(如果前四个中的三个需要更长的时间,这很可能是相同的)在第六个工作,依此类推.现在,如果您的异常值是 MATLAB 选择处理循环迭代的顺序的 20、850 和 900 号,并且每个需要 100 倍的时间,这仅意味着第 21 到 320 次迭代将由四名工作人员中的三名解决,而一个是忙于 20 日(到 320 日将完成,现在假设非异常值计算时间的分布大致均匀).然而,分配到第 850 次迭代的工作人员将继续运行,即使在另一个解决了 #1000 之后,#900 也是如此.事实上,如果大约有 1100 次迭代,第 900 次的迭代应该在其他的时候大致完成.

You did not say exactly what you observe, but what you describe is well consistent with dynamic workload distribution: First, the four (example) workers work on one iter each, the first one that is finished works on a fifth, the next one that is done (which may well be the same if three of the first four take somewhat longer) works on a sixth, and so on. Now if your outliers are number 20, 850 and 900 in the order MATLAB chooses to process the loop iterations and each take 100 times as long, this only means that the 21st to 320th iterations will be solved by three of the four workers while one is busy with the 20th (by 320 it will be done, now assuming roughly even distribution of non-outlier calculation time). The worker being assigned the 850th iteration will, however, continue to run even after another has solved #1000, and the same for #900. In fact, if there were about 1100 iterations, the one working on #900 should be finished roughly at the time when the others are.

[编辑,因为原始措辞暗示 MATLAB 仍会按从 1 到 1000 的顺序分配 parfor 循环的迭代,不应假定]

[edited as the orginal wording implied MATLAB would still assign the iterations of the parfor loop in order from 1 to 1000, which should not be assumed]

长话短说,除非你先找到一种方法来处理你的异常值(这当然需要你先验地知道哪些是异常值,并找到一种方法让 MATLAB 用这些开始 parfor 循环处理),仅靠动态工作负载分配无法避免您观察到的效果.

So long story short, unless you find a way to process your outliers first (which of course requires you to know a priori which ones are the outliers, and to find a way to make MATLAB start the parfor loop processing with these), dynamic workload distribution alone cannot avoid the effect you observe.

补充:但是,我认为,当您观察到循环接近完成时,评估异常值的工人*s* 继续运行"似乎至少意味着以下之一

Addition: I think, however, that your observation that as "the loop nears completion, the worker*s* that evaluated the outliers continue to run" seems to imply at least one of the following

  1. 异常值以某种方式出现在 MATLAB 开始处理的最后一次迭代中
  2. 你有很多工人,按照迭代次数的数量级
  3. 您对异常值 (2-3) 数量的估计或其计算时间损失(因子 100)的估计过低

这篇关于Matlab并行计算工具箱,parfor循环中工作的动态分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:45