* The primary motivation for using Pthreads is to realize potential program performance gains.
* When compared to the cost of creating and managing a process, a thread can be created with much less operating system overhead. Managing threads requires fewer system resources than managing processes.
For example, the following table compares timing results for the fork() subroutine and the pthreads_create() subroutine. Timings reflect 50,000 process/thread creations, were performed with the time utility, and units are in seconds, no optimization flags.
Note: don't expect the system and user times to add up to real time, because these are SMP systems with multiple CPUs working on the problem at the same time. At best, these are approximations.
* All threads within a process share the same address space. Inter-thread communication is more efficient and in many cases, easier to use than inter-process communication.
* Threaded applications offer potential performance gains and practical advantages over non-threaded applications in several other ways:
o Overlapping CPU work with I/O: For example, a program may have sections where it is performing a long I/O
operation. While one thread is waiting for an I/O system call to complete, CPU intensive work can be performed by
other threads.
o Priority/real-time scheduling: tasks which are more important can be scheduled to supersede or interrupt lower
priority tasks.
o Asynchronous event handling: tasks which service events of indeterminate frequency and duration can be
interleaved. For example, a web server can both transfer data from previous requests and manage the arrival of
new requests.
* The primary motivation for considering the use of Pthreads on an SMP architecture is to achieve optimum performance. In particular, if an application is using MPI for on-node communications, there is a potential that performance could be greatly improved by using Pthreads for on-node data transfer instead.
* For example:
o MPI libraries usually implement on-node task communication via shared memory, which involves at least one memory
copy operation (process to process).
o For Pthreads there is no intermediate memory copy required because threads share the same address space within a
single process. There is no data transfer, per se. It becomes more of a cache-to-CPU or memory-to-CPU bandwidth
(worst case) situation. These speeds are much higher.
o Some local comparisons are shown below:
Pthreads Worst Case
MPI Shared Memory Bandwidth Memory-to-CPU Bandwidth
Platform (GB/sec) (GB/sec)
AMD 2.4 GHz Opteron 1.2 5.3
IBM 1.9 GHz POWER5 p5-575 4.1 16
IBM 1.5 GHz POWER4 2.1 4
Intel 1.4 GHz Xeon 0.3 4.3
Intel 1.4 GHz Itanium 2 1.8 6.4
进程跟线程的区别是我明白的, ^_^
[Quote=引用 4 楼 chaojiew 的回复:]
Although the definition of a process may seem obvious, the concept of threads makes all of this less clear-cut. A thread allows a single program to run in multiple places at the same time. All the threads created (or spun off) by a single program share most of the characteristics that differentiate processes from each other. For example, multiple threads that originate from the same program shar…
[/Quote]