[NTLUG:Discuss] pthreads on Linux
Steve Baker
sjbaker1 at airmail.net
Sat Aug 11 10:57:02 CDT 2001
"Peter A. Koren" wrote:
>
> I just wrote a threaded version (pthreads) of a C program which has one
> main thread and typically 50 to 100 child threads. I have an ABIT BP-6
> dual processor motherboard and am running Mandrake 8.0 with SMP kernel
> version 2.4.3. I was hoping to get a speed up. No such luck.
One dirty little secret of PC architecture is that most programs of
this nature end up being main-memory-bandwidth bound.
If that's the case, adding more CPU's (or even faster CPU's) probably
won't help because they are all still fighting over the same physical
RAM chips using the same bus.
You should take a careful look at the memory access patterns of your
calculation and see if you can restructure the data that your
threads operate on to make it more cache-coherent. Keep all the
memory locations that each thread needs in as small an address range
as possible - and keep the data that each thread is using well separated
from that of the other threads. That maximises the chance that the
data can stay in the cache memory of each CPU rather than having to
be repeatedly refetched from main memory.
Having 50 or 100 threads probably doesn't make a lot of sense - but
two threads (for two CPU's) probably would.
There are a lot of "PROBABLY"'s in that because a lot depends on
the precise nature of your memory accesses. I'm far from an expert on
this subject - but I know that in some cases people have speeded up
applications by an order of magnitude just by rearranging the order
of the elements in an array!
----------------------------- Steve Baker -------------------------------
HomeMail : <sjbaker1 at airmail.net> WorkMail: <sjbaker at link.com>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sf.net http://tuxaqfh.sf.net
http://prettypoly.sf.net http://tuxkart.sf.net
http://freeglut.sf.net http://toobular.sf.net
More information about the Discuss
mailing list