In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, Xiaobian will bring you about how to understand. NET 4 parallel programming. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
1. The difference between parallel programming and multithreaded programming.
1.1 Parallel programming.
Now with the popularity of multi-core computers, parallel programming technology, that is, multi-core programming technology is gradually known as the mainstream of development. For this reason, parallel programming was introduced in. NET 4. A number of libraries and classes in. NET 4 provide support for parallel programming, such as Task Parallel Library,Parallel LINQ, etc.
In fact, there are some implementations of parallel programming technology in. NET 1.0--multithread technology. The problem with multithreading *** is that it is difficult to use and manage. In the use of multithreading, because of its complexity, we tend to distract ourselves from using multithreading. Our original purpose was concealed.
1.2 Compare differences
The underlying mechanism of concurrent programming proposed in. NET 4 is based on multithreading. But the difference between them is that parallel programming in. NET 4 is easier.
In the traditional programming model, programmers are responsible for creating threads, assigning tasks to threads, and managing threads. A figurative metaphor: You have a group of soldiers, you give them orders, and then you have to keep an eye on your soldiers to make sure they do what you want. (Tired!)
Parallel programming in. NET 4 relies on the Task Parallel Library(TPL). In TPL, the most basic execution unit is task(Chinese can be understood as "task"), a task represents an operation you want to perform. You can define a task for each operation you want to perform, and TPL is responsible for creating threads to execute the tasks you define and managing threads. TPL is task-oriented and automatic; traditional multithreading is human-oriented.
The Task mechanism allows us to focus on the problem we are trying to solve. If previous multithreading techniques made us give up some use of parallel programming, then the new parallel programming techniques in. NET 4 can help us regain confidence.
Despite the new parallelism techniques, traditional multithreading techniques are still useful. When we use parallelism in TPL to execute multiple tasks, we don't have to worry about creating threads at the bottom, managing threads, etc.
2. Advantages and disadvantages of parallel programming techniques
The advantage of using parallel technology *** is that it improves the performance of the system. Parallel processing generally works like this: a task to be performed is broken down into many small parts, and these small parts are then executed on different processors (which can be one computer with multiple cores or many computers). Because these many small parts are executed simultaneously, they are called "parallel."
The following questions need to be considered when using and programming:
1. Cost issues.
Parallel execution isn't free, it costs money. There is overhead in starting and managing parallel runs, just as there is overhead in creating and managing threads. The more tasks you have to perform in your program, the better the parallelism will be.
2. Harmonization of data
If the small pieces executing in parallel need to share common data, then we need to coordinate. In general, the more data that needs to be reconciled, the greater the performance penalty for parallel execution. If the implementation of each small part is independent, then we do not have to coordinate. But a lot of times, we need coordination. And coordination techniques are not difficult, as will be described in later articles.
3. How much better performance?
Adding a computer's CPU might speed up a program, but not absolutely. We know that an application doesn't necessarily (and often doesn't) run as long on a single-core computer as on a dual-core computer.
1/2. Therefore, parallel programming does not necessarily improve the performance of the program exponentially. Because performance depends on many factors, hardware is a big factor.
3. When to adopt parallel programming
Advice: If a problem can be solved with parallel programming, use it, otherwise don't. It sounds like crap, but it's really good advice. Because parallel programming is not ***, it can only
Solve a class of problems, so analyze the problem before using it. If a problem can indeed be solved with parallel solutions, but with many factors, such as some of the problems we mentioned earlier. Weighing the costs and benefits of using it before deciding whether to use it.
The above is how to understand. NET 4 parallel programming shared by Xiaobian for everyone. If you happen to have similar doubts, you may wish to refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.