 # A Question from Programming Massively Parallel Processors: A Hands-on Approach

Consider a hypothetical block with 8 threads executing a section of code
before reaching a barrier. The threads require the following amount of time
(in microseconds) to execute the sections: 2.0, 2.3, 3.0, 2.8, 2.4, 1.9, 2.6, and
2.9 and to spend the rest of their time waiting for the barrier. What percentage
of the total execution time of the thread is spent waiting for the barrier?

The longest time spent by any thread before reaching the barrier is 3.0us. After 3.0us, then, no threads are waiting for the barrier - the barrier has been satisfied.

The total execution time of 8 threads in this scenario (up through the point of satisfaction of the barrier) is 8*3.0us = 24us. The amount of time that threads spend waiting for the barrier must be computed using each thread, it is:

``````24 - (2.0+2.3+3.0+2.8+2.4+1.9+2.6+2.9) = 24 - 19.9 = 4.1us
``````

That number, expressed as a percentage of the total execution time, is:

``````(4.1/24)*100% = 17.083%
``````

If we assume 2 sig figs, I would say 17%

1 Like

Thank you, I understand your solution but my point is that why we consider the total execution time 8 *3us. As the threads start simultaneously together, the total execution time would be 3us, the one which restricts other threads’ execution. I mean it only takes 3us the instruction done by all the threads, not 24us.
Can you guide me where is my misunderstanding?

Because I’m unable to propose a sensible answer with your definition of total execution time = 3.0us

I don’t think my definition is absurd or unprecedented. In fact, by default, the linux `time` tool, when measuring a multithreaded application, reports the CPU time as the sum of the CPU times encountered by each thread, even if they are all concurrent. So one can witness a reported CPU time that is many times longer than the actual application duration. This is not difficult to demonstrate, try it. The alternative definition here would be I suppose “wall clock” time.

I cannot give you an authoritative answer because I did not write or contribute to that book. Perhaps you have an answer key? You or others may have a different view, I won’t debate it any further. That is how I would answer the question.

Both definitions of execution time have their various uses. If you have a cogent solution to the question based on wallclock time of 3.0us, please suggest it!

1 Like