简体   繁体   English

高效的并行握手(组合)

[英]Efficient parallel handshaking (combinatorics)

While programming parallel programs a lot of time I encounter with problem of making something with unique group of 2 values. 在编写并行程序的大量时间中,我遇到了用2组值的唯一组合制作某些东西的问题。 In other words this is handshaking problem where each man has to shake his hand with everyone else's. 换句话说,这是握手问题,每个人都必须与其他人握手。 After handshaking there is a dinner waiting for all participants. 握手后,有晚餐在等待所有参与者。

There are 2 approaches I'm aware of how to do this: 我知道有两种方法可以做到这一点:

  1. Number all men and make it parallel for each man, who will shake hands with men that have lower number. 给所有男人编号,并使每个男人平行,这些男人将与人数较少的男人握手。 Dinner will be cold before man with last number asks everyone to shake his hand. 晚饭要冷,然后最后一个号码的人要大家握手。

  2. We will tell everyone how much participants there are and create condition based on that value, so everyone will shake aprox. 我们将告诉每个人有多少参与者,并根据该值创建条件,以便每个人都将摇摇晃晃。 equal number of hands in parallel. 相等数量的平行手。 Dinner will be cold because participants are bad at math. 晚餐会很冷,因为参与者数学不好。 (In this case people can act like someone else) (在这种情况下,人们可以像其他人一样行事)

We can also exchange men for numbers and shaking for comparing, multiplying, etc. The problem is that we want eat that dinner before it is cold and waiting for one thread or making lot of conditions will slow the process down. 我们还可以将人换成数字,并摇晃以进行比较,乘法等。问题是,我们希望在凉爽之前吃晚餐,等待一个线程或进行很多条件会减慢该过程。

Is there other more efficient way to do this? 还有其他更有效的方法吗?

I'm not sure how much you are constrained by "bad at math" but you might have a look at How to automatically generate a sports league schedule , with good answer that refers to http://en.wikipedia.org/wiki/Round-robin_tournament . 我不确定您有多少会受到“数学不好”的约束,但是您可以看看如何自动生成体育联赛时间表 ,其良好答案是http://en.wikipedia.org/wiki/ Round-robin_tournament

In working out how efficient or not a synchronisation primitive is, you need to keep track separately of time spent waiting for lagging processes to catch up, and time spent in the synchronisation itself. 在确定同步原语的效率如何时,您需要分别跟踪等待滞后进程追赶所花费的时间以及同步本身所花费的时间。 If your time is actually being spent waiting for laggards to catch up, you need to speed them up (eg by spreading work around more evenly) or avoid the necessity of waiting for them - speeding up what happens after everybody has waited for everybody else may not help much. 如果您实际上是在花时间等待落后者赶上,则需要加快它们的速度(例如,通过更均匀地分散工作)或避免等待它们的必要-加快每个人都在等待其他人之后可能发生的情况没有太大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM