1

My program is a simple recursive implementation of the factorial function. Is its execution speed related to the number of processors on my computer? My program is not multi-threaded.

Cel Skeggs
  • 1,827
  • 21
  • 38
  • Possible duplicate of [Why does a single threaded process execute on several processors/cores?](http://stackoverflow.com/questions/8485947/why-does-a-single-threaded-process-execute-on-several-processors-cores) – Raymond Chen May 28 '16 at 03:29
  • @RaymondChen that question is relevant but it's a distinct question, not a duplicate. – Cel Skeggs May 28 '16 at 04:46
  • It is not that straight-forward. The more cores you have, the less likely your program will be slowed down because another program is competing for the processor. But such a program can also raise the processor chip temperature, forcing it to reduce the clock rate. Which slows down your program. The way most machines are used, the most likely correct answer is "no". – Hans Passant May 28 '16 at 09:21

1 Answers1

2

No, it is not related to the number of processors. Since your program is not multithreaded, it will run in only a single thread, which runs on a single processor at a time.

The speed of a single processor is not increased by the existence of other processors on a computer, except that having more processors may allow other programs to run on other cores, thus allowing your program to use a larger fraction of the single processor that it is running on.

As Raymond Chen pointed out in the comments, there are also complicated issues with caching that may come up if your thread is migrated across CPUs, which occurs regularly.

Of course, these are likely to be relative small effects overall - and, certainly, you generally can't expect a program to run faster on a computer with more processors unless the program is multithreaded.

Cel Skeggs
  • 1,827
  • 21
  • 38
  • 1
    It may affect the performance if the thread migrates from one processor to another (say because the original processor is busy handling an interrupt), because the new processor won't have the workload in cache. – Raymond Chen May 28 '16 at 03:23