Suvichara

Concurrent programming gets a new lease of life

Posted by Prashant Hegde on September 1, 2007

Concurrent programming has been around for some time now. Programmers have been writing multi-threaded applications wherever they can. So, what has changed now?

According to Herb Sutter, the free lunch is over. Processor manufacturers had been coming up with faster and faster processors for some time. But, now, it looks like they have hit the physical limit. Now processors aren’t getting any faster anymore. Instead, the processor manufacturers are now putting more than one processor on a single chip i.e multicore processors. What difference does that make to us? According to Herb Sutter it is going to change the way we program, think about the program logic, debug, test etc. He has summarized the trends:

  1. Applications will increasingly become concurrent if they want to fully exploit the CPU throughput
  2. Applications are likely to become increasingly CPU bound
  3. Efficiency and performance will get more important
  4. Programming languages and systems will increasingly be forced to deal with concurrency

People who are familiar with lock-based programming might think that moving their programs to new multi-core systems should work just fine. This, however, need not be true. The true parallel execution might expose some of the inherent race conditions. They need to prepared for some surprise if they move their so called ‘concurrent application’ to multi-processor systems. This trend will force people to think in a different way i.e think in terms of concurrency. People still need to carefully design their applications for achieving better performance as before. The complexity of algorithms still matter.

Some of the tricks that can speed up your application include:

  • Data-structures should be designed such that less or no synchronization needed for accessing them from different threads
  • Application’s working set should, as much as possible, fit into the cache. This reduces the memory access and speeds up the application
  • Perform loop optimizations
  • Try to reduce the algorithm complexity. If you can reduce your algorithm complexity from O(n2) to O(n long(n)) you will witness significant speed up
  • Align data ( 32 or 64 byte boundaries depending on the machine architecture)
  • Use compiler features for exploiting processor architecture related features
  • Some operations can be made faster using SIMD, MIMD instructions

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>