Load balancing challenges in multicore programming _php tutorial

Source: Internet
Author: User
In multi-core CPUs, it is important to ensure that the tasks assigned to each CPU have a good load balance in order to perform the performance of multiple CPUs well. Otherwise, some CPUs are running, others are idle, and they are not able to perform the benefits of multicore CPUs.


To achieve a good load balance there are usually two scenarios, one is static load balancing and the other is dynamic load balancing.


1. Static load Balancing


Static load balancing, the need to manually split the program into several parallel execution of the parts, and to ensure that the split into the various parts can be distributed evenly across the CPU to run, that is, the workload must be distributed across multiple tasks, so that the high acceleration coefficient.


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


Although the problem of NP-complete is mathematically difficult, it is not a problem in the title, because the NP-complete problem can generally be solved by finding an effective approximate algorithm.


2. Dynamic load Balancing


Dynamic load balancing is the goal of load balancing the assignment of tasks in the course of a program's operation. In fact, there are many problems that can not be solved by static load balancing, such as a large loop, the number of cycles is input by the external, do not know the number of cycles beforehand, it is difficult to achieve load balance using static load balancing strategy.


The scheduling of tasks in dynamic load balancing is usually 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 tasks, scheduling algorithm can not be very good, so dynamic load balancing may not meet 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 achieved, because even though there are gaps in the execution time of the tasks allocated on each CPU, the increase in CPU cores always causes the total execution time to decrease, increasing the acceleration factor with the increase in CPU count.


The difficulty with load balancing is that the number of parallel execution blocks in a program can be divided by programmers, and of course, when CPU cores are low, such as dual-core or 4-core, this partitioning is not very difficult. But as the number of cores increases, the granularity of the division becomes finer, and by the time the 16 cores are over, 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 to run, to manually divided into 128 tasks, its division of the difficulty imaginable.


The error of the load partition will be amplified with the increase of CPU cores, such as a program that requires 16 time units to be executed on 4 tasks, the average load execution time on each task is 4 units of time, the dividing error is 1 units of time, then the acceleration coefficient becomes 16/(4 1) = 3.2, is the ideal case of the acceleration coefficient of 4 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, if the number of cores increases again, due to the amplification of the error, The acceleration coefficient decreases compared to the ideal acceleration factor.


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


If a lock is used, some seemingly balanced loads may also become unbalanced due to lock contention.


4. Coping Strategies for load balancing


For software with less computational power, even on a single-core CPU that runs fast and does not have much impact on load balancing, the actual load balancing takes into account large computational and large-scale software that requires load balancing on multiple cores to better utilize multicore to improve performance.


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


Another strategy is at the tool level, that is, the compilation tool can assist in the decomposition of parallel blocks manually, 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 cores.


http://www.bkjia.com/PHPjc/445099.html www.bkjia.com true http://www.bkjia.com/PHPjc/445099.html techarticle in multi-core CPUs, it is important to ensure that the tasks assigned to each CPU have a good load balance in order to perform the performance of multiple CPUs well. Otherwise some CPUs are running, and some other CPUs are ...

  • 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.