多线程比单线程慢 [英] Multi-threading slower than single thread

查看:131
本文介绍了多线程比单线程慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我已经使用C ++构建了一个多线程,与使用Windows XP(决斗核心和guad核心)在单线程上运行该程序相比,我的计算时间得到了改善.这是预期的.

但是,与在单线程上运行时相比,在多线程上,该程序在Windows Server 2003上运行速度较慢.该服务器具有24个核心,我可以看到所有24个核心都在工作.

您认为问题可能是什么?

欢呼声

Ken

Hi there,

I''ve built a multithreading using C++, I get improvement in computation time compared to when the program is run on single thread using Windows XP (duel core and guad core). This is expected.

However, the program runs slower on Windows Server 2003 when multithreaded compared to when the program is run on single thread. This server has 24 cores and I can see that all 24 cores are working.

What u think the problem could be?

Cheers

Ken

推荐答案

我猜想通信开销正在成为一个问题,大概线程正在花费过多的时间进行通信并等待其他线程来完成任务.显然,使用较少数量的内核并不会成为问题,但是一旦您获得更大数量的内核,它就会成为问题.这可能是最大粒度的问题,可以尝试从问题中提取出来,即在许多内核上运行时,您将工作分成了很小的块,或者可能是通信和线程同步扩展方式的问题. br/>
在没有更多详细信息的情况下,很难给出更详细的解释.
I would guess that the communication overhead is becoming a problem, presumably the threads are spending an excessive amount of time communicating and waiting for other threads to complete tasks. Apparently, this doesn''t become a problem with a small number of cores but once you hit larger numbers it does. This could be a problem with the maximum granularity it is sensible to try and extract from the problem, i.e. you are splitting the work into too small chunks when running on many cores or could be a problem with how your communication and thread synchronisation scale.

It''s hard to come up with a more detailed explanation without more details of what is happening.


内核间和IO通信以及线程粒度很可能是这里的问题,因为例如,访问当前位于RAM或光盘上的数据的示例将被证明是有问题的.

这不会在较少的内核上显示出来,在这些内核上您可能对获取数据的需求较少,但是在具有众多内核且将任务分解为更小的卡盘的进程的系统上,IO访问将增加,并且您将无法获得改善.在这种情况下,性能会下降.

您会惊讶于访问RAM的瓶颈是多少...
Inter-core and IO communication coupled with thread granularity is most likely the issue here, for example accessing data that is currently sat in RAM or on Disc will prove problematic.

This wouldn''t show itself on fewer cores where you may have less requirement to fetch data, however on systems with numerous cores with a process that is splitting tasks down in to smaller chucks IO access will increase and you will get no improvement or as in this case see a decline in performance.

You''d be surprised how much of a bottle neck accessing RAM is...


阅读^ ]文章:它提供了有关处理多线程应用程序时可能发生的情况的详细信息...
Read this[^] article: it gives detailed informations about what can happen when dealing with multi-threaded applications...


这篇关于多线程比单线程慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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