C # parallel programming-related concepts

Source: Internet
Author: User
Original article: C # parallel programming-related concepts

For more information, see the C ++ concurrent programming high-level tutorial.

Background

Today's computers have at least one dual-core microprocessor, which is very common with quad-core and eight-core computers. The era of having multiple kernels on a single processor is approaching, modern microprocessor provides a new multi-core architecture. Therefore, it is very important for software design and coding to make full use of the functions of these architectures.

Multi-core microprocessor

Multi-core microprocessor has many different complex micro-architectures, designed to provide stronger parallel execution capabilities, increase throughput, reduce potential performance bottlenecks, reduce power consumption, and reduce heat consumption. Therefore, many modern microprocessors can increase or decrease the clock frequency of each core based on the workload, or even sleep the kernel that is not in use. When these kernels are needed, the operating system will wake them up again.

Hardware thread and software thread

A multi-core processor has more than one physical kernel. Each physical kernel may provide multiple hardware threads, also known as the logical kernel or logical processor.

In Windows, each running program is a process. Each process creates and runs one or more threads, also known as software threads ), there is only one thread in a process. This thread is called the main thread ).

The operating system scheduler shares available processing resources fairly among all processes and threads to run, and allocates processing time to each software thread, when the Windows scheduler runs on a multi-core microprocessor, the scheduler must allocate time from the hardware threads supported by the physical kernel to a software thread that needs to run commands.

Windows recognizes each hardware thread as a scheduling logic processor, and each logic processor can run software thread code, processes running multiple software threads can give full play to the advantages of hardware threads and physical kernels and run commands in parallel. In Windows, the processing time of a worker block is allocated to each available hardware thread, and hundreds of thousands of software threads are run in this way.

Task-based parallel design rules

1. divide each problem into many sub-problems without considering the execution sequence of sub-problem tasks (data that can be processed in parallel and data stream that can be processed in a complex parallel manner)

2. Consider the necessity of connecting tasks without issues and avoid dependencies between tasks.

3. Reduce the critical section between tasks.

Advantages and disadvantages of parallel Tasks

1. The running and management of parallel tasks require overhead. The more tasks that need to be executed in the program, the better the parallel effect.

2. The more resources or data shared in a parallel task, the higher the execution performance loss of the parallel task. If the resources of each task exist independently, the performance will be much better.

Multithreading

Multithreading refers to the technology for implementing concurrent execution of multiple threads on software or hardware. A computer with multithreading capability can execute more than one thread at a time with hardware support, this improves the processing capability.

Differences between multithreading and parallel computingReference http://blog.csdn.net/delacroix_xu/article/details/5928121

Essentially, there is no difference. multithreading is not only used for parallel computing, but also has other functions (for example, reducing blocking. In the single-core era, the function of multithreading to eliminate blocking is called "concurrency ", this is essentially different from parallelism)

Parallel Computing can also be achieved through other means, and multithreading is only one method (such as multi-process)

The writing is a bit messy. You may want to take a look at the relationship among the Windows scheduler, multi-core microprocessor, hardware thread, software thread, and good constraints on concurrent task development, I hope you will correct this.

 

Sakya monk Source: http://www.cnblogs.com/woxpp/p/3924476.html
The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent and provide a connection to the original article on the article page.

C # parallel programming-related concepts

Related Article

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.