![]() However, you have to write asynchronous or synchronous/non-blocking I/O code, and the relatively small performance improvement won't always justify the extra complexity. Note that the optimal behaviour with I/O bound code is typically still to have at most one thread per pipeline/core/CPU. Sadly I think the metaphor will get completely out of control if I try to justify this with buckets. Here, the context switch which is so costly compared to execute-bound code, is pretty cheap compared to I/O bound code. This is only the case if they share no data (and avoid any cache collisions).Īs a couple of people have suggested, for I/O the limiting resource might be the number of usefully queueable I/O operations: this could depend on a whole host of hardware and kernel factors, but could easily be much larger than the number of cores. Note also we're assuming the threads are entirely independent. Whether the limiting execution resource (bucket) is a CPU, or a core, or a hyper-threaded instruction pipeline for your purposes depends on which part of the architecture is your limiting factor. That is, two threads taking turns on a core typically accomplish less work than a single thread running twice as long: this is because of the extra work done to switch between the two threads. Additionally, we should stress that passing a bucket from one person to another is typically slower than a single person just carrying the bucket the same distance. ![]() Adding more threads doesn't help if they can't do anything. So you want to have as many people as can do some work (use a bucket) simultaneously.Ī person here is a thread, and a bucket represents whichever execution resource is the bottleneck. If you have 5 or more people, then at least one of those people If you have 1-3 people then you're missing out on using some buckets. You want to move all the water from one to the other, and have 4 buckets. Imagine you have two swimming pools, one full and one empty. "Why does this happen?" is kind of easy to answer. That can easily be the limiting factor in practical applications. Limited I/O speed (hard disk and network "speed").This theoretical prediction (about CPU times) does not consider others practical bottlenecks as CPUs/Cores) sharing the same physical processor/core (it's a form of multitasking, as pointed in another answer). Remember that threads can be processed (depending on implementation and hardware available, e.g. Given that you are using threads (and not physical processors) the situation can be even worse than this. at most 4 times) even if you use more and more processors to do the work.Īs a rule of thumb, the more of you program that you cannot transform in parallel execution, the less you can obtain using more execution units (processors). ![]() 75%) of a program you can speed up execution only so far (e.g. The Amdahl's law predict that for every given parallel portion (e.g. For example, there can be a 25% of time spent in strictly sequential operations, and the remaining 75% of time is spent in operation that can be executed in parallel. This portions can be expressed as a percentage of execution time. The point of Amdahl's law is that in any program (in any algorithm) there is always a percentage that can not be run in parallel (the sequential portion) and there is another percentage that can be run in parallel (the parallel portion). ) and can give some general insight about this class of problems. In the field of parallel computing there is Amdahl's law that can be applicable (or cannot, not but you do not describe the details of you problem, so. As other have pointed out ( slm answer, EightBitTony answer) this is a complicated question and more so since you do not describe what you threads do and how they do it.īut definitively throwing in more threads can make the things worse.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |