0

They say an i5 7500T has 4 cores (so, in this case 4 threads). When I, for instance, calculate the 1 millionth Fibonacci number (single thread only, every number is dependent on its predecessor) using Python, it takes 5,5 seconds. When I start 2 of these processes simultaneously, they both take 6,3 seconds and when I start 3 or 4 it takes even longer (10+ seconds per process).

How can this be called 'multi-core'? When I use a big server with several cores, 1 to n processes when n < number of cores all take the same amount of time with varying n.

2
  • If you are using a recursive algorithm try switching to an iterative one as it should be a lot more efficient in this scenario and scale better.
    – James P
    Sep 26, 2018 at 15:42
  • Just using this: def fib(n): a,b = 1,1 for i in range(n-1): a,b = b,a+b return a print (fib(1000000))
    – Niels
    Sep 26, 2018 at 17:42

1 Answer 1

1

Each core is individually fast, but they all need access to shared resources such as caches and memory. As a result multi-core work increases the amount of work you can do, but also can cause bottlenecks.

Your mathematical calculations probably are very memory constrained and you are hitting the limit of your memory bandwidth.

That it takes 5.5 seconds on one core, but using two cores takes 6.3 seconds means you did twice as much work in only 0.8 seconds longer rather than the 5.5 seconds longer (11 seconds total) that doing the work serially would have taken. You effectively saved yourself 4.7 seconds of real world time (11 - 6.3) by doing the work side by side instead of one after the other.

Multi core does not mean you can perfectly do twice the amount of work in the same amount of time, but it does mean that you can achieve a meaningful amount more than you could have achieved with only one core.

If it now takes 10 seconds for all processes to finish when using all 4 cores then it has still finished faster than if you had done the work four times on a single core, where it should have taken 22 seconds. You are achieving four times the work in less than twice the time.

3
  • Multi-threading is a case of Diminishing returns.
    – harrymc
    Sep 26, 2018 at 15:30
  • Still wondering why, in some systems, it takes the same amount of time per process when running them simultaneously...
    – Niels
    Sep 26, 2018 at 17:45
  • Because those systems have higher end processors and dual-, triple- or even quad-channel memory which has far increased memory bandwidth would be a basic guess. Without know what the other systems are we can only make wild guesses.
    – Mokubai
    Sep 26, 2018 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .