Visual C + + 2010 new features: Parallel computing

Source: Internet
Author: User
Tags visual studio 2010

Performance is always a problem for programmers to consider. In the single nuclear era, even in the era of dual-core (multi-core), it is generally through improving the performance of the client's computer performance, such as increasing the server, memory, configuration load balance and other means to achieve, we call this process to enjoy the performance of free dinner. There is no free lunch, no free meal can not be endless, in fact, there are new solutions in parallel computing. Parallel computing is like a great feast to be talked about, in this article we use the analogy of cooking, through the analysis of the performance of the free meal, using Visual Studio C + + 2010 This sharp weapon, the parallel programming model of the great gourmet side of the parallel development.

Performance Free dinner is over

By boosting CPU computing power, you can actually improve application performance. But in reality, no matter how much processor performance increases, the software has a way to quickly swallow. Moreover, the computer hardware is constrained by physical limits, the processor frequency of the upgrade has encountered a bottleneck. So the days of enjoying a free meal are over, and the industry is no longer able to provide exponential growth in faster processors, but only more processors that provide exponential growth. Multicore will lead to fundamental changes in software development.

In the current computer market, multi-core computers have sold far more than one-core computers, and multi-core has become a mainstream. In this trend, if you run a single core application to a 64-core machine, you will see that the task Manager shows that only 1/64 of the computing power is available:

Figure 1 Task Manager shows a single thread application running on 64 nuclear machines, with only one kernel in the calculation

As you can see from the example above, traditional applications no longer have the natural ability to achieve higher performance returns on higher-end hardware devices, and applications that give full play to the performance of hardware devices are the mainstream of future software development, and what are the choices we face as developers? Herb Sutter The answer explicitly in his original text: Parallel computing. If "concurrency will be another major change in the history of software development" is a forecast four years ago, parallel computing has become one of the core trends of software development today. For programmers, the day after the free meal is over, you can only cook in person.

There 's a problem in cooking yourself.

As we all know, application development, with complete lifecycle management, is complicated by a range of behaviors, from writing requirements specifications, programming manuals, to coding, debugging, and performance optimization, to testing, releasing, and later maintenance. Parallel computing is to add a dimension to the original complexity of the program development. In this process, the programmer encounters a variety of problems, as shown in the following illustration:

Figure 2 issues to consider for developing concurrent applications

Developing parallel applications has always been a headache for programmers, and what are we prepared for today? As the saying goes, the Qiao daughter-in-law is difficult to bricks without straw, some prepared ingredients, a reference menu, a set of convenient use of kitchenware is essential, I hope these essential products for our cooking to bring convenience.

ingredients, recipes and kitchenware are important.

In 2007, Microsoft announced the creation of a parallel computing platform group dedicated to simplifying the development of parallel applications. With the release of Visual Studio 2010 and the. NET Framework 4, Microsoft provides a complete solution for parallel computing.

Figure 3 Support for concurrent development in Visual Studio 2010 and. NET Framework 4

when the food material is running concurrently

Whether it is task parallelism, data parallelism, or pipeline parallelism, it means that a time-consuming task or data needs to be split into smaller units. The granularity of segmentation is often determined by the nature of the task. The benefits of fine granularity parallelism are mainly embodied in scalability and load balancing. Assuming that a time-consuming task is only roughly split into four subtasks and executed concurrently, its scalability for more than four-core machines is not good enough, and even if it is running on a quad-core machine, it is not possible to perform real-time dynamic load balancing, and three subtasks may occur early. And yet another task is in the tragic event of a nuclear waiting.

To support fine-grained parallelism, a concurrent programming framework is provided in Visual C + + 2010 to support commonly used collaborative task scheduling and hardware resource (CPU and memory) management. The. NET Framework 4 is also based on an existing thread pool (thread pool), The collaborative task scheduling and work stealing (work-stealing) algorithms are implemented. The work-stealing algorithm takes advantage of fine-grained parallelism to ensure that idle threads "steal" tasks from local, global and even other threads ' task queues in a certain order. Of course, the default task scheduler can be extended or configured to support special scheduling policies.

The Concurrency Runtime is a C + + concurrent programming framework that simplifies parallel programming to help us write reliable, scalable, and responsive parallel applications.

Recipe Programming Model

A high level of abstraction and unified programming pattern is an important direction to simplify the development of parallel programs. As a result, many new language and library features are seen in Visual Studio 2010 and. NET Framework 4, as well as a series of task-oriented parallel structures and algorithms.

In Visual C + + 2010, the Parallel Pattern Library (Parallel) introduces tasks (tasks) and task Groups concepts that support task parallelism. A task is a class of computations that can be decomposed into more granular computations. In the parallel pattern library, Task_handle contains code that executes fine-grained granularity to represent a task. Task handles (task_handle) are important because they manage the lifetime of encapsulated work functions. For example, when a Task_handle object is passed to a task group, the Task_handle object must remain valid until the task group completes. A task group is used to organize, schedule, wait for, or cancel a task or tasks, it pushes a task into a work-stealing queue, the scheduler removes the task from the queue, and executes the task with the available compute resources. The following sample code performs several tasks concurrently

To make it easier to change a serial application to a parallel application, the parallel Schema Library provides parallel_for and Parallel_for_each, and it's easy to rewrite the for and For_each Loop code that we write for concurrent execution without reducing the readability of the Code; , for pipeline parallelism, the Agent library (Agents Library) provides a C + + Template Library based on the data flow programming model that can be used to isolate access to shared resources to improve scalability by using message passing to transfer state changes between objects. The advantage of messaging is that it binds to the data synchronously, rather than to the external synchronization object. This simplifies data transfer between components and eliminates programming errors in the application.

In the context of managed code, the Task Parallel Library (Parallel) introduces System.Threading.Tasks.Task classes, as well as Parallel.For and Parallel.ForEach, to support task or data parallelism.

Also worth mentioning is PLINQ (Parallel language-integrated Query). As a parallel implementation of LINQ, PLINQ partitions The IEnumerable data source in memory, and then operates on the sub data source in parallel with multi-core in the system.

Whether it's organization, scheduling, execution, resource allocation, and memory sharing for tasks, Visual C + + 2010 is helping to write concurrent applications that enhance software performance by leveraging Multi-Core CPU performance to truly enjoy the culinary performance of the meal.

Kitchenware Development Tools

Zi Yue: "工欲善其事, its prerequisite". A good development tool is half the success. In Visual Studio 2010, two new debugger windows and a new Performance Visualization Profiler (Profiler) are included. With these two debugger windows, we can debug on the same abstraction level as the task, see the status of the task, the relationship between each other, call stack, and so on. Of course, if you are interested, you can also see the threads of the task and take advantage of a global unified view to see the call stacks of all the threads and the relationships between them.

Figure 4 Parallel Stack Window

Figure 5 Parallel Task window

Performance optimization is an important work in the software development process, then a full-featured performance Explorer is naturally necessary. The parallel Performance Visual Profiler in Visual Studio 2010 can see the application's use of resources, which part of the program is limited by the amount of computation, or the execution of threads, the reason for blocking, the fact that threads switch between different cores, and so on; At the same time, it is possible to jump to the corresponding call stack at different points in the thread execution to study the root cause of threading blocking.

Figure 6 Probe View CPU utilization

Figure 7 Probe View Threads

Summary

We are accustomed to the problem of serial thinking, which is called thinking, for the sudden parallel thinking, it takes some time to be able to accept; second, parallel application development is a bit harder than ordinary programs. Changing this way of thinking about serial (sequential) programming and accepting such programming challenges requires a process of understanding and learning. For the time being, for most programmers who develop concurrent applications, it is still time to start with the serial application and determine the performance bottleneck and then parallel the critical code segments. With Visual Studio 2010 and the. NET Framework 4 As a sharp weapon, with a parallel programming model such good ingredients, programming is like cooking, only hands-on to realize the endless fun, what are you waiting for? Hurry up and ACT!

Original link: http://tech.it168.com/a2010/1215/1138/000001138613.shtml

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.