Hot answers tagged

180 votes

Does it ever make sense to use more concurrent processes than processor cores?

The canonical time when you use far, far more processes than cores is when your processes aren't CPU bound. If your processes are I/O bound (either disk or more likely network), then you can ...
user avatar
107 votes
Accepted

Which programming language is used to write a BIOS program?

BIOSes used to be written exclusively in assembly language, but the transition was made a long time ago to write the majority of the code in some higher level language, and leave written in assembly ...
user avatar
  • 31.4k
93 votes
Accepted

How does a single thread run on multiple cores?

The operating system offers time slices of CPU to threads that are eligible to run. If there is only one core, then the operating system schedules the most eligible thread to run on that core for a ...
user avatar
  • 32.3k
82 votes
Accepted

Is a 1 < 10 comparison less expensive than 1 < 1000000?

Every processor I've worked on does comparison by subtracting one of the operands from the other, discarding the result and leaving the processor's flags (zero, negative, etc.) alone. Because ...
user avatar
  • 19.9k
62 votes
Accepted

In software programming, would it be possible to have both CPU and GPU loads at 100%?

Theoretically yes, but practically it's rarely worth it. Both CPUs and GPUs are turing-complete, so any algorithm which can be calculated by one can also be calculated by the other. The question is ...
user avatar
  • 22.8k
59 votes
Accepted

Why should your code not use 100% CPU?

If cooling is insufficient, the CPU might overheat. But they all (well, at least all modern PC CPUs) feature various thermal protection mechanisms which will throttle the clock speed or, as a final ...
user avatar
58 votes

Does it ever make sense to use more concurrent processes than processor cores?

Short answer: Yes. Longer answer: Set your magic number stupid high, benchmark it, set it low, benchmark it again, and keep doing that until you have your answer. The number of moving parts here is ...
user avatar
  • 1,105
45 votes
Accepted

Why do executables depend on the OS but not on the CPU?

Executables do depend on both the OS and the CPU: Instruction Set: The binary instructions in the executable are decoded by the CPU according to some instruction set. Most consumer CPUs support the ...
user avatar
  • 124k
45 votes

Why would a program require a specific minimum number of CPU cores?

It may be possible to do this "by accident" with careless use of core affinity. Consider the following pseudocode: start a thread in that thread, find out which core it is running on set its CPU ...
user avatar
  • 9,263
41 votes

Why is multithreading not used everywhere?

Why multithreading isn't everywhere? Because … I understand that multi-threading is hard to implement and has drawbacks if number of threads is less than expected.
user avatar
36 votes

In software programming, would it be possible to have both CPU and GPU loads at 100%?

It is not related to game programming. Some scientific code can also use both the GPU and the CPU. With careful -and painful- programming, e.g. by using OpenCL or CUDA, you could load both your GPU ...
user avatar
34 votes

Why would a program require a specific minimum number of CPU cores?

It could be necessary to have 4 cores because the application runs four tasks in parallel threads and expects them to finish almost simultaneously. When every thread is executed by a separate core ...
user avatar
  • 22.8k
28 votes
Accepted

Why is multithreading not used everywhere?

The proliferation of multi-core CPUs is predominantly driven by supply, not by demand. You're right that many programmers don't bother decomposing their systems so that they can profit from multiple ...
user avatar
27 votes

How does a single thread run on multiple cores?

There is no such thing as a single thread running on multiple cores simultaneously. It doesn't mean, however, that instructions from one thread cannot be executed in parallel. There are mechanisms ...
user avatar
  • 1,794
26 votes

How does a single thread run on multiple cores?

summary: Finding and exploiting the (instruction-level) parallelism in a single-threaded program is done purely in hardware, by the CPU core it's running on. And only over a window of a couple ...
user avatar
26 votes

Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?

As you may have noticed, there's a category of application that tries really hard to avoid input lag and only occasionally fails at doing so: games. Even then it's not uncommon for players to notice ...
user avatar
  • 9,263
25 votes

Is a 1 < 10 comparison less expensive than 1 < 1000000?

Is there a difference in performance on the ALU level in comparisons between very large numbers vs very small ones? It's very unlikely, unless going from a small number to a large number changes your ...
user avatar
25 votes

Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?

I would like to answer this question from more of a high-level, marketing perspective than a more low-level, technical one. All of the current mainstream Operating Systems are so-called general ...
user avatar
24 votes

Why do we have to wait for I/O?

It's possible to write asynchronous IO where you tell the OS to dispatch a disk read/write and then go do something else and then later check if it's done. It's far from new. An older method is using ...
user avatar
23 votes

Why is multithreading not used everywhere?

Why multithreading isn't everywhere? Frame challenge: but it is everywhere. Let's see, let's name some platforms: Desktops/laptops: one of the most common applications today is the browser. And to ...
user avatar
  • 5,134
22 votes

Japanese Multiplication simulation - is a program actually capable of improving calculation speed?

This multiplication algorithm does not replace multiplication with addition. Instead, it splits the multiplication into a number of smaller multiplications that are easier for humans to understand. ...
user avatar
  • 124k
21 votes
Accepted

Why do we have to wait for I/O?

The I/O schemes you are describing are in current use in computers. why the CPU actually has to stay there, practically not doing anything else than just waiting for IO? This is the simplest ...
user avatar
  • 4,136
20 votes

Is a 1 < 10 comparison less expensive than 1 < 1000000?

Many processors have "small" instructions which can perform arithmetic operations, including comparisons, on certain immediately-specified operands. Operands other than those special values must ...
user avatar
  • 8,113
20 votes
Accepted

How does sleeping a thread work?

There is much more involved in running a program than just the code within that program. Any program that runs in a multi-process OS is under the control of the OS's scheduler, and the scheduler does ...
user avatar
20 votes

Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?

Why can't (or why don't) operating systems absolutely prioritise user input (and repainting thereof) in threading and process scheduling? Even if the operating system tells the application about the ...
user avatar
  • 9,804
18 votes

Understanding memory update propagation in x86/x86-64 CPU L1/L2/L3 caches and RAM

First if you are concerned about recent (last 5-10 years, since Nahalem?) Intel x86 architecture, then you're a little off in your description of the caches. Each core has their own 128K L1 cache ...
user avatar
  • 351
18 votes

How does sleeping a thread work?

As Doc Brown mentioned in a comment, interrupts are the key, and not just for sleeping. An interrupt is a hardware signal that the processor should stop what it's doing and run a piece of code. ...
user avatar
  • 5,180
18 votes
Accepted

Why do compilers typically only generate executables for the platform they are installed on?

what makes it difficult for say the visual C++ compiler on windows to generate a linux binary executable file? Other than an unwillingness to do that on Microsoft's part, absolutely nothing. The ...
user avatar
  • 19.9k
16 votes

Why should your code not use 100% CPU?

There is generally nothing wrong with a program using 100% CPU while it is actually doing useful work and is not taking time away from anything more important. If a particular hardware platform is e....
user avatar
  • 8,113
16 votes

Why would a program require a specific minimum number of CPU cores?

It is unlikely that these "minimum requirements" represent something below which the game will not run. Far more likely is that they represent something below which the game will not run with ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible