P
PJ6
I'm pushing my CPU to its limit with a realtime physics simulation to learn
more about coding for performance. In the simplest case, I have a form that,
on a timer tick, drives the physics model forward by the time elapsed since
the last tick measured by a stopwatch (since both the timer and DateTime.Now
is not accurate), and then renders the newly calculated state to the UI.
Now I noticed that when I pushed this process to its limit, I see only 50%
load. That's OKsince in theory this application is executing on only one
thread and my CPU has two cores. I wanted to see if I could get more
performance, so I've been playing around with using both a BackgroundWorker
and a normal Thread to run the non-UI part of the phsyics engine. In both
cases, on a timer tick, if the thread is not busy the UI renders, then tells
the thread to continue calculating by stepping forward by a certain
timespan.
OK this is the part that I don't get. When I use a separate thread,
performance goes DOWN, and processor utilization goes DOWN. I see the CPU
core usage flip, but the total processor usage maxes out at around 47%,
lower than the 50% I see with a single thread. So I'm looking at how both
cores are being used a little more closely... I was expecting to see one
processor maxed out, and the other nearly idle. Not so! In both the single
and multi-threaded model, I get 1/4 usage with one core and 3/4 usage with
the other. I'm starting to suspect that there aren't really two 'cores' in
the sense that I can get double the processing power of 50%.
I'm just getting into performance computing and not very versed in
multithreading yet, could anyone lend me some insight?
Thanks,
Paul
more about coding for performance. In the simplest case, I have a form that,
on a timer tick, drives the physics model forward by the time elapsed since
the last tick measured by a stopwatch (since both the timer and DateTime.Now
is not accurate), and then renders the newly calculated state to the UI.
Now I noticed that when I pushed this process to its limit, I see only 50%
load. That's OKsince in theory this application is executing on only one
thread and my CPU has two cores. I wanted to see if I could get more
performance, so I've been playing around with using both a BackgroundWorker
and a normal Thread to run the non-UI part of the phsyics engine. In both
cases, on a timer tick, if the thread is not busy the UI renders, then tells
the thread to continue calculating by stepping forward by a certain
timespan.
OK this is the part that I don't get. When I use a separate thread,
performance goes DOWN, and processor utilization goes DOWN. I see the CPU
core usage flip, but the total processor usage maxes out at around 47%,
lower than the 50% I see with a single thread. So I'm looking at how both
cores are being used a little more closely... I was expecting to see one
processor maxed out, and the other nearly idle. Not so! In both the single
and multi-threaded model, I get 1/4 usage with one core and 3/4 usage with
the other. I'm starting to suspect that there aren't really two 'cores' in
the sense that I can get double the processing power of 50%.
I'm just getting into performance computing and not very versed in
multithreading yet, could anyone lend me some insight?
Thanks,
Paul