. Parallel Programming Technology in NET4 (also called multi-core Programming Technology) 2

Source: Internet
Author: User
This series of articles will give a comprehensive introduction to parallel programming technology (also called multi-core programming technology) and applications in. net4. The topics in this article are as follows: 1. Differences between parallel programming and multi-threaded programming. 2. Advantages and Disadvantages of Parallel Programming Technology 3. When to adopt parallel programming 1. Differences between parallel programming and multi-threaded programming. 1.1 parallel programming. Now with multi-core computing

This series of articles will give a comprehensive introduction to parallel programming technology (also known as multi-core programming technology) and applications in. NET 4. The topics in this article are as follows: 1. Differences between parallel programming and multi-threaded programming. 2. Advantages and Disadvantages of Parallel Programming Technology 3. When to adopt parallel programming 1. Differences between parallel programming and multi-threaded programming. 1.1 parallel programming. Now with multi-core computing

This series of articles will give a comprehensive introduction to parallel programming technology (also known as multi-core programming technology) and applications in. NET 4.

The topics in this article are as follows:
1. Differences between parallel programming and multi-threaded programming.
2. Advantages and Disadvantages of Parallel Programming Technology
3. When to adopt parallel programming

1. Differences between parallel programming and multi-threaded programming.

1.1 parallel programming.
Now with the popularization of multi-core computers, parallel programming technology, that is, multi-core programming technology, is also known as the mainstream of development. To this end, "parallel programming" is introduced in. NET 4 ". Libraries and classes of some columns in. NET 4 provide support for Parallel programming, such as Task Parallel Library and Parallel LINQ.


In fact, some implementations of parallel programming technology are available in. NET 1.0-multiline thread technology. The biggest problem with multithreading is that it is difficult to use and manage. Because of its complexity, multithreading is often used to distract us from multithreading. This masks our initial purpose.

1.2 comparison
The underlying mechanism of parallel programming proposed in. NET 4 is actually based on multithreading. But their biggest difference before is that parallel programming in. NET 4 is more convenient.


In the traditional programming model, programmers are responsible for creating threads, assigning tasks to threads, and managing threads. A metaphor: you have a group of soldiers, and then you give them commands, then you must always monitor your soldiers and ensure they do what you want. (Tired !)


In. NET 4, Parallel programming relies on Task Parallel Library (TPL. In TPL, the most basic execution unit is a task (which can be understood as a "task" in Chinese). A task represents an operation to be executed. You can define a task for each operation you want to execute. TPL is responsible for creating a thread to execute the task you define and managing the thread. TPL is task-oriented and automatic, while traditional multithreading is manual-oriented.


The Task mechanism enables us to focus on the problems we want to solve. If the previous multi-thread technology makes us abandon the use of some parallel programming, the new parallel programming technology in. NET 4 will allow us to build confidence again.


Although new parallel technologies are available, the traditional multi-thread technology is still very useful. When we use the parallel technology in TPL to execute multiple tasks, we do not have to worry about the underlying thread creation and management threads.

2. Advantages and Disadvantages of Parallel Programming Technology
The biggest advantage of using parallel technology is to improve the system performance. The parallel processing process is generally like this: a task to be executed is split into many small parts, and then these small parts are separately on different processors (can be a multi-core computer, it can also be executed on many computers. Because many small parts are executed at the same time, it is called "Parallel ".
When using parallel programming, consider the following:

1. Overhead issues.
Parallel execution is not free, but overhead. Both the start and Management of Parallel Running require overhead, just like the creation and management of threads. In a program, the more tasks you want to execute, the better the effect of using parallelism.


2. Data coordination
If a small part of the parallel execution needs to share public data, we need to coordinate. Generally, the more data to be coordinated, the larger the performance loss of parallel execution. If each part of the execution is independent, we do not need to coordinate it. But in many cases, we need to coordinate. In addition, the coordination technology is not very difficult, and will be described one by one in subsequent articles.


3. Performance Improvement
Adding a computer's CPU may increase the program's running speed, but it is not absolute. We know that an application runs on a single-core computer for a certain period of time (often not ).
1/2. Therefore, adopting parallel programming may not necessarily multiply the program performance. Because performance is related to many factors, hardware is a big factor.

3. When to adopt parallel programming


Suggestion: if a problem can be solved through parallel programming, it will be used; otherwise, it will not be used. It sounds nonsense, but it is indeed a good suggestion. Because parallel programming is not omnipotent
To solve the first-class problem, we need to analyze the problem before using it. If a problem can be solved using a parallel solution, there are many factors that affect it, as we mentioned earlier. The overhead after use is weighed and the difference between whether or not to use. Many examples will be provided in subsequent articles.

I want to write it here for the time being. I have talked a lot about it in theory. I hope my friends in the garden will forgive me! From the next article, we will use the code + explanation form.
Note: I haven't written anything for a long time, :). I hope you will forgive me!

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.