NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: optimize for multicore processors



On Mon, 9 Nov 2009 09:21:54 -0200
Otavio Augusto <otavioti%gmail.com@localhost> wrote:

> I'm a litle question about programming for multicore CPUs
> 
> For extract more performace in multiore machines I need a specific
> technique or an
> multi-thread programming is sufficient ?
> 

If you are programming in C on Unix operating system, then Pthreads API
will be the most portable way to do parallel programming. Some
compilers (GNU and Sun Studio) support OpenMP, which allows you to use
C language pragmas to do parallel programming. I think OpenMP uses
operating system's Pthreads library, so Pthreads is the lowest common
denominator when it comes to multi-threading.

1. Get a good book on Pthreads programming. I would recommend
"Programming with Posix Threads" by David R. Butenhof.

2. When you know how to use Pthreads, sit down and think hard about how
to partition your data into multiple jobs and then schedule those jobs
to multiple threads. Some multicore processors support a few parallel
threads, some supports hundreds (Sun UltraSparc). Things to think about
are:

- What's the maximum number of parallel threads to create?
- Are those threads persistent, or are they created dynamically as
workload increases and then destroyed?
- How do you queue parallel jobs, how do you manage the queue and
schedule jobs to threads?
- What algorithms/data structures are the most efficient and involve
least contention on the shared data?

3. Finally optimise your programs. Looks at the hardware documentation
for various multicore processors. Look at how L1 and L2 caches are
organised, find out sizes of cache lines. Structure your data so as to
increase spatial locality and to minimize false sharing.


I would also recommend reading the following book on high performance
computing:

http://wikis.sun.com/display/BluePrints/(Book)+Techniques+for+Optimizing
+Applications+-+High+Performance+Computing


Home | Main Index | Thread Index | Old Index