Matlab并行计算工具箱,在parfor循环中动态分配工作 [英] Matlab parallel computing toolbox, dynamic allocation of work in parfor loops

查看:142
本文介绍了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:

工作分配是动态的.没有分配固定的工作分配 迭代范围,仅在之后才为工作人员分配新的迭代 他们完成了对当前迭代的处理,结果是 甚至工作量分配."

"Work distribution is dynamic. Instead of being allocated a fixed iteration range, the workers are allocated a new iteration only after they finish processing their current iteration, which results in an even work load distribution."

关于发生了什么的任何想法?

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,完成的第一个工作人员工作在第五个工作上,完成的下一个(如果前四个中的三个花费更长的时间,则可能会相同)在第六个上工作,依此类推.现在,如果您的离群数是20、850和900的顺序(按MATLAB选择处理循环迭代的顺序,并且每个都花费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循环中动态分配工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆