Click here to Skip to main content
15,613,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 28-May-18 23:08pm

1 solution

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.
 
Share this answer
 
Comments
Member 13849020 29-May-18 5:13am    
Ok thank you very much, I understood that the number of processors and the speed of my program aren't directly related, but why the most expensive functions with one processors aren't the same with 4?
CPallini 29-May-18 5:35am    
5.
Daniel Pfeffer 29-May-18 7:52am    
One possibility is that with more processors, less switching-in and switching-out of threads is necessary. This means that the internal data/instruction cache of each processor is not flushed so often, which in turn means that the functions in general execute more quickly.

Note that this is only a guess. It would be impossible to give you a better answer without a full analysis of the profiling data.
Member 13849020 29-May-18 8:36am    
yes of course! Thank you for your time!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900