On Thu, 19 Apr 2007 04:30:20 -0700, Coaster <Co*****@Coaster.netwrote:
I am designing a process which will spawn a good number of threads and
some of them will execute a c++ process which is quite memory intensive
(although not multithreaded). This will run on a 2 cpu (both dual core)
server. What do I need to do if anything in order to spread the
workload across the cpu's / cores in order to tune it properly?
Nothing really. Keep in mind that for CPU-intensive tasks, it doesn't do
any good to have more threads than you have processors, and in fact adding
more than that many threads will only slow things down due to the context
switch costs. If your tasks involve a lot of i/o, then having lots of
extra threads can help by allowing new work to be started or finished
while other threads are waiting for i/o to complete. It's okay to have a
few extra threads, but if you have too many runnable threads (not waiting
on i/o or other things) at once they will just spend a lot of time
fighting over the processor(s).
Multi-threaded algorithms can get very complicated, there are lots of
little details to get right, and lots of different ways to optimize how
things work. So sure, in that sense you can do lots to ensure that your
code is "tuned properly". But fundamentally, the main goal is to have
just enough threads to ensure that there's exactly one thread that is
runnable for each processor on the computer. If you do that, Windows will
take care of the rest.
The links you posted aren't, I don't think, very relevant to your
question. They do address some relatively esoteric issues related to
multi-threading programming, but I don't think they should affect you.
The same general rules apply.
Pete