Load-balancing challenges in multi-core programming

Source: Internet
Author: User
Tags execution

Multi-core CPU, to play a good performance of multiple CPUs, you must ensure that the task assigned to each CPU has a good load balance. Otherwise some CPUs are running, others are idle and cannot play the advantage of multi-core CPUs.


There are usually two scenarios for achieving a good load balance, one is static load balancing and the other is dynamic load balancing.


  1. Static load Balancing


In static load balancing, it is necessary to divide the program into several parts that can be executed in parallel, and to ensure that all parts of the partition can be distributed evenly to each CPU, which means that the workload should be uniformly distributed among many tasks, so as to achieve high acceleration coefficient.


The problem of static load balancing is mathematically a NP-complete problem, with Richard M. Karp, Jeffrey D Ullman, Christos H. Papadimitriou, M. Garey, D. Johnson and others in 1972 to 198. In the past 3 years, the NP-completeness of static load problem under several different constraints is proved.


Although the problem of NP completeness is difficult in mathematics, this is not the problem in the title, because the NP-complete problem can generally find a very effective approximation algorithm to solve.


  2. Dynamic load Balancing


Dynamic load balancing is the purpose of assigning tasks to load balance during the process of running a program. In fact, there are many problems can not be solved by static load balancing, such as a large cycle, the number of cycles are imported from the outside, do not know the number of cycles in advance, it is difficult to achieve load balance by static load balance partitioning strategy.


The scheduling of tasks in dynamic load balancing is generally implemented by the system, programmers can only choose the dynamic balance of the scheduling strategy, can not modify the scheduling strategy, because there are many uncertainties in the actual task, scheduling algorithm can not be done very well, so dynamic load balancing may sometimes not reach the established load-balancing requirements.


3. Where is the problem of load balancing?


The problem with load balancing is not how much load-balancing is going to be, because even though there are some gaps in the execution times of tasks allocated on each CPU, the increase in the number of CPU cores increases the total execution time, with the increase in the size of the CPUs.


The difficulty with load balancing is that many of the parallel execution blocks in a program are divided by programmers, and of course it is not difficult to divide the number of CPUs, such as dual-core or 4-core. But as the number of cores increases, the granularity of division becomes more and more thin, and when it comes to more than 16, it is estimated that programmers will be mad about how to divide tasks. For example, a sequence of code execution, put on the 128-core CPU running, to manually divided into 128 tasks, its division of the difficulty imaginable.


The error of load partition will enlarge with the increase of CPU kernel number, for example, a program that requires 16 units of time to execute on 4 tasks, the average load execution time for each task is 4 units of time, the partition error is 1 units of time, then the acceleration coefficient becomes 16/(4+1) = 3.2, is ideally 4 of the acceleration factor of 80%. But if you put it on a 16-core CPU, if the partition error of a task is 0.5 units of time, then the acceleration coefficient becomes 16/(1+0.5) = 10.67, only the ideal acceleration factor of 16 66.7%, if the kernel number increases, due to the enlargement of the error, The ratio of acceleration coefficients to the ideal acceleration factor decreases.


The problem with load partitioning is also reflected in the CPU and software upgrades, such as a balanced load partition on the 4 core CPU, but at 8 and 16, the load may have become unbalanced. Software upgrades are the same, when the software added functionality, load balance will be destroyed, but also need to reassign the load to achieve balance, so that software design difficulty and trouble greatly increased.


If a lock is used, some seemingly balanced load may become unbalanced as a result of lock competition.


  4. The coping strategy of load balance


For software with less computational capacity, even if it is running on a single core CPU, it is fast load balancing does not have a lot of impact, the actual load balancing to consider the large computation and the large scale software, these software needs to load balance on multi-core to better use multi-core to improve performance.


For large-scale software, the response strategy of load balancing is to develop the macro partitioning method of dividing parallel blocks, from the whole software system level to partition, rather than the traditional for some local programs and algorithms for parallel decomposition, because local programs are often difficult to break down into more than dozens of tasks to run.


Another coping strategy is at the tool level, that is, the compiler can assist in the decomposition of parallel blocks, and find a good decomposition scheme, which Intel has made some efforts, but also need more efforts to make the tool more powerful to deal with the situation when the number of nuclear.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.