Variable execution speed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application that consists of a managed C++ wrapper around an
unmanaged C++ "engine" that performs a very processor intensive task. In
the application I create two instances of the managed wrapper (and therefore
of the unmanaged engine) on separate threads so that it can be working on two
scenarios at the same time. The engine keeps track of certain counters so
that I can monitor it's progress.

However, I'm finding that the engine executes at different speeds on
different occasions when I run the application with exactly the same
scenarios. In fact, sometimes one instance of the engine runs at the speed
I'm expecting and the other runs at about one tenth of the normal speed, even
though they are instances of exactly the same code, running on a dual core
processor with nothing else running at the same time.

I find myself running the application, checking the speed, and, if it's not
running at the normal speed I shut it down, start it again, check the speed,
etc, until, for no apparent reason, it starts up running at full speed. It's
the only way I can find to get the application working at full potential on
both threads and it's very annoying!

Does anyone have any idea what might be causing this? I'm still a C++
beginner so I'm hoping this can be fixed with a compiler option or two.

I'm using VC++ 2005 on a Pentium D and Win2K.

Thanks in advance.
 
However, I'm finding that the engine executes at different speeds on
different occasions when I run the application with exactly the same
scenarios. In fact, sometimes one instance of the engine runs at the
speed
I'm expecting and the other runs at about one tenth of the normal speed,
even
though they are instances of exactly the same code, running on a dual core
processor with nothing else running at the same time.

Does anyone have any idea what might be causing this? I'm still a C++
beginner so I'm hoping this can be fixed with a compiler option or two.

I'm using VC++ 2005 on a Pentium D and Win2K.

What are your threads doing? Are they working on the same data? Do they use
global data / file io/ synchronization mechanisms like mutexes, events or
critical sections?
There are a lot of things that influence the perfromance of parallel
programmed threads. We need some more info to help you.
 
The threads are completely distinct. They are created by (and the code that
they execute is in) different instances of the same class. They do not share
any variables, memory or any other resources. The objects are initialized
with a "scenario" and then are set running in order to "solve" it (which can
take seconds, minutes or even hours depending on the scenario). The
processing consists entirely of processing in memory.

The latest thought I have is that the problem is not due to the threading at
all but rather due to caching on the CPU (though I really have no idea about
the mechanics of caching - it's a wild guess). The scenarios allocate lots
of relatively small amounts of memory during initialization. Perhaps these
bits of memory are being fragmented in some cases and are messing up the
caching so that there are lots of cache misses, slowing down the processing.
I'm currently working on allocating all of the memory in one block to see if
that has any effect.

My only other thought is that it's just a "feature" of the CPU or Win2K.
I've noticed Visual Studio being affected by something similar. Sometimes it
will seem to be running really slowly. For example, selecting multiple lines
of text by scrolling down (using the down arrow) while holding the shift key
down is very slow; compiling takes longer than usual. Once I shut VS down
and start it up again everything happens at normal speed.
 
Back
Top