Subj : Re: One thread on several processors in multiprocessor system? To : comp.programming.threads From : Randy Date : Tue Feb 01 2005 06:08 pm Julius wrote: > Hello, > > I never thought befor deep about threads, but. I know that one thread > can run on separate processor. but, can one thread runs on several > processors? Say, simultaneously calculating sqrt(2), in one processor, > and 2+2 on another? > > For example in the code: > > ... > > double x = sqrt(2); > int i = 2 + 2; > .... This sort of 'threading' happens routinely today on out-of-order CPUs, even without the assistance of the compiler. Operands are dispatched by Tomasulo's algorithm (for example) from multiple reservation stations as soon as they become available (arriving from memory or from earlier operations) and the scheduler decides they can be executed independently. In this case, even code compiled without any optimization will probably execute concurrently on the CPU, perhaps by employing two different floating point functional units. Of course, no real threading is involved in this case, just asynchronicity. But threading does arise via something called Simultaneous MicroThreading (SMT), AKA Hyperthreading (Intel's TM, as in the Pentium4). SMT also occurs at the discretion of the CPU, as it toggles among existing independent threads of execution, mapping them onto and off of the CPU's resources as peripheral resources (esp. operands to/from RAM) become available or unavailable, respectively. There's been a lot of research into the potential for concurrent execution throughout the average program. I think the conclusion is that perhaps 80% of the average program's instructions could execute concurrently with others, assuming that 1) hardware resources were available, and 2) that the instructions could be correctly identified on-the-fly as being independent (on-the-fly, because branches play havoc with a program's control and data dependencies). Randy -- Randy Crawford http://www.ruf.rice.edu/~rand rand AT rice DOT edu .