使用的处理器数量完全改变了我的代码分析 [英] The number of processors used totally change my code profiling

查看:89
本文介绍了使用的处理器数量完全改变了我的代码分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有一个简单的问题:为什么使用分析工具编译代码时使用的处理器数量不会减少每个函数所花费的时间?例如,如果我第一次用1个处理器编译,然后用4个编译器,我希望看到相同的扁平配置文件(比如相同的百分比和相同的最昂贵的函数等),但只是花费在每个函数上的时间除以四。但事实并非如此......我有一个完全不同的功能列表,时间不连贯。为什么??

PS:我使用Gprof。

谢谢!



我的尝试:



我尝试使用一个然后两个然后四个处理器,每次我都有一个完全不同的分析...我真的不知道我能做什么,这是什么意思。

Hello everyone!
I have one simple question: why the number of processors used when I compile my code with a profiling tool doesn't decrease the time spent in each function? For example, if I compile the first time with 1 processors, and then with four, I expect to see the same flat profile (like the same percentage and the same most expensive functions etc..) but just with the time spent in each function divided by four. But it's not the case... I have a totally different list of functions and the time is not coherent. Why??
PS: I use Gprof.
Thanks!

What I have tried:

I tried to use one then two then four processors and every time I have a totally different profiling.. I really don't know what I can do and what does that mean.

推荐答案

函数通常在单个线程的上下文中执行。拥有额外的处理器不会提高其速度。



当您的程序可以划分为多个线程时,其他处理器非常有用。在这种情况下,处理器越多,可以同时执行的线程越多(真正的多任务处理,而不是时间分片)。这有限制(参见Amdahl定律)和问题(例如线程之间的同步)。



多任务需要一种不同于单任务的编程方法,但要正确实施它可以显着加快许多程序。
A function is typically executed in the context of a single thread. Having additional processors won't improve its speed.

Additional processors are useful when your program can be divided into multiple threads. In this case, the more processors, the more threads may be executed simultaneously (true multi-tasking, not time-slicing). This has limits (see Amdahl's Law), and problems (e.g synchronisation between threads).

Multi-tasking requires a different approach to programming than single-tasking, but properly implemented it can significantly speed up many programs.


这篇关于使用的处理器数量完全改变了我的代码分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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