Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the boundaries of learning multicore programming?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the realms of learning multi-core programming". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the realm of learning multi-core programming"?

The basic ideas of the layer are several basic ideas mentioned in the article "Laozi is a great multicore computing scientist": "greed", "selfishness", "stealing" and so on. These things are innate, they are a kind of human instinct, and they can be regarded as methods and strategies, so this layer is called "innate method strategy layer".

Innate methods and strategies are not limited to "greed", "selfishness" and "stealing". At last year's SD conference, I talked about a distributed memory management algorithm based on snatch, which showed that "snatch" is also a congenital method strategy. The so-called:

"at the beginning of people, sexual greed, sexual selfishness, sexual theft, sexual robbery."

In order to avoid misunderstanding, let's make it clear here that the words "steal" and "rob" are not exactly the same as those in the usual sense. "stealing" and Taoist stealing have the same meaning, that is, "do not take"; "snatch" means "do not return".

The former Fan Li Yun said, "if you take it from heaven, you will take the blame." Since God has given us so many good methods and strategies, it is obviously a waste not to use it. Detailed code examples of how to use these strategies in multicore programming can be found in the open source project TBB.

The second layer is the target demand evaluation layer.

Innate method and strategy, although it may seem simple, it is not easy to make good use of it. Innate methods such as selfishness, greed, theft and robbery can be used to do both good and bad things. This involves the problem of how to evaluate whether these innate methods and strategies are well used, that is, the problems that need to be solved in the second level of target requirements evaluation.

We can not use it in order to use the innate method strategy, but use it to meet our needs and achieve certain goals. So what are the needs and goals?

I don't want to analyze the general requirements here, but only the requirements of optimization. In order to achieve optimization, it can be understood as the effective use of various resources, and many people may already have this understanding [1]. These resources can be divided into the following aspects:

Time resources, time resources refer to time, such as how long a program or algorithm needs to run.

Space resources, such as memory, hard disk, network, all kinds of IO equipment resources, all belong to space resources.

Energy resources, which usually refer to the consumption of electric energy, have become more and more important due to the softening of the world and the increasing importance of environmental protection.

How to make effective use of the above resources and achieve a balance among the use of various resources is not only the basis for the formulation of goals and requirements, but also the basis for evaluating the degree of optimization of procedures or algorithms.

The third layer of essential root security layer

The effective use of resources is not a simple matter. In the single-core era, many programmers have rich experience in the utilization and balance of time and space resources, and there is almost no need to consider the utilization of computing resources because there is only one processor.

However, in multi-core systems, the use of computing resources has become the number one problem, and the use of multiple processors makes programmers have to consider how to execute programs in parallel on each processor, which involves a load balancing problem.

The problem of load balancing has always been a difficult problem. Due to the objective existence of a large number of shared resources, a variety of different shared resources are complex, and the load can not be simply distributed to each CPU core. So what is used to ensure load balancing? How to meet the target requirements for the effective use of resources?

To ensure the realization of the target demand, the core is the issue of fairness and justice. Of course, there are many interpretations of the two words fairness and justice in reality. Here, a broader interpretation is adopted. Any definition that can be logically deduced from the correct premise is regarded as justice. For example, all axioms, theorems and inferences in natural science belong to justice. In human society, some recognized moral standards and legal provisions also belong to justice.

Take the dynamic stealing scheduling algorithm as an example, it is generally designed that each thread steals one task at a time, in fact, it has implicitly used fairness and justice to limit the number of stolen tasks, if not, allow one thread to steal all the tasks in the queue at one time, then other threads will not be able to steal the tasks, which will lead to load imbalance and unable to effectively use the computing resources of multiple processors.

Another example is the memory allocation algorithm based on grabbing. After each thread uses the shared memory, it does not return to its main thread, but takes it as its own. For a long time, some threads must occupy too much memory resources. In order to solve this problem, the solution is to judge whether you have too much memory after each grab, and if you have too much memory, you will take the initiative to return part of the memory to the public memory pool, so as to achieve load balancing. It can be seen that fairness and justice are also used in the memory allocation algorithm based on snatch to ensure load balancing.

The problem of fairness and justice can be said to be the foundation of the algorithm and the source of global efficiency. Why would you say that? Take a look at the current subprime crisis in the United States, the root cause of which is caused by banks extending loans to customers who are insolvent. From the perspective of fairness and justice, in essence, the bank violates the basic issue of fairness and justice for its own greed and selfishness. There is no need for me to say more about the consequences of the subprime crisis, as we all have seen. It can be seen that there is no justice, greed, selfishness and other innate methods and strategies will inevitably be abused, the result will inevitably lead to the overall non-excellence.

The essence, root and guarantee in the name of this layer refers to fairness and justice.

It should be mentioned that in the reality of human society, because people have emotions, there will always be deviations in the implementation of fairness and justice, and benevolence is needed to make up for its deficiency. This may be the fundamental reason why Confucianism has been around for more than two thousand years. Of course, if the thought of benevolence is also regarded as a part of moral standards, according to the previous definition of justice, benevolence also belongs to the category of justice.

The fourth layer algorithm implements the execution layer.

Through the exposition of the above three levels, we can know that the innate method and strategy is the basic means to achieve optimization, and the effective use of resources is the target demand and evaluation condition to achieve optimization. fairness and justice are the prerequisites to ensure the rational use of innate methods and strategies. Is it possible to achieve the final result of optimization with these things?

The answer is "no". If the above things can achieve the optimization results, then I'm afraid you can write a good multicore program by grabbing anyone from the street. Why do you need a programmer? why do you need to learn various patterns, techniques and algorithms of multicore programming?

Just like learning Newtonian mechanics, some people can design skyscrapers and build all kinds of machines, while others can do nothing. Why so? Use the difference between the good and the bad. In order to write a good multi-core program, it also involves the problem of how to use the basic principles and methods in the above three layers, but to make good use of these basic principles, it depends more on the knowledge and ability of the programmer. Ultimately, it depends on the specific implementation of the algorithm or program. Just like with Taoism and Confucianism, there are still hundreds of scholars in various fields, such as legalists, farmers, doctors and so on.

At this point, I believe you have a deeper understanding of "what is the realm of learning multi-core programming". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report