views:

346

answers:

11

As a software developer dealing mostly with high-level programming languages I'm not sure what I can do to appropriately pay attention to the upcoming omni-presence of multicore computers. I write mostly ordinary and non-demanding applications, nevertheless I think it is important to know if I need to change any programming paradigms or even language to master the future.

My question therefore:
How to deal with increasing multicore presence in day-by-day hacking?

+2  A: 

In general, become very friendly with threading. It's a terrible mechanism for parallelization, but it's what we have.

If you do work with .NET, look at the Parallel Extensions. They allow you to easily accomplish many parallel programming tasks.

Cody Brocious
+3  A: 

Learn the benefits of concurrency, and the limits (e.g. Amdahl's law).

So you can, where possible, exploit the only route for higher performance that is going to be open. There is a lot of innovative work happening on easier approaches (futures and task libraries), and old work being rediscovered (functional languages and immutable data).

The free lunch is over, but that does not mean that there is nothing to exploit.

Richard
+2  A: 

To benefit from more that just one core you should consider parallelizing your code. Multiple threads, immutable types, and a minimum of synchronization are your new friends.

Michael Damatov
+2  A: 

I think it will depend on what kind of applications you're writing.

Some kind of apps benefit more of the fact that they're run on a mutli-core cpu then others. If your application can benefit from the multi-core fact, then you should be ready to go parallel. The free lunch is over; that is: in the past, your application became faster when a new cpu was released and you didn't have to put any effort in your application to get that extra speed. Now, to take advantage of the capabilities a multi-core cpu offers, you've to make sure that your application can take advantage of it. That is: you've to see which tasks can be executed multithreaded / concurrently, and this brings some issues to the table ...

Frederik Gheysels
+2  A: 

Learn Erlang/F# (depending on your platform)

Matt Briggs
+5  A: 

Herb Sutter wrote about it in 2005: The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software

Null303
A: 

I've been asked the same question, and the answer is, "it depends". If your Joe Winforms, maybe not so much. If your writing code that must be performant, yes. One of the biggest problem I can see with parallel programming is this: if something can't be parallized, and you lie and tell the run-time to do in parallel anyways, it's not going to crash, it's just going to do things wrong, and you'll get crap results and blame the framework.

Chris
+4  A: 

Most problems do not require a lot of CPU time. Really, single cores are quite fast enough for many purposes. When you do find your program is too slow, first profile it and look at your choice of algorithms, architecture, and caching. If that doesn't get you enough, try to divide the problem up into separate processes. Often this is worth doing simply for fault isolation and so that you can understand the CPU and memory usage of each process. Also, normally each process will run on a specific core and make good use of the processor caches, so you won't have to suffer the substantial performance overhead of keeping cache lines consistent. If you go for a multi process design and still find problem needs more CPU time than you get with the machine you have, you are well placed to extend it run over a cluster.

There are situations where you need multiple threads within the same address space, but beware that threads are really hard to get right. Race conditions, especially in non-safe languages, sometimes take weeks to debug; often, simply adding tracing or running under a debugger will change the timings enough to hide the problem. Simply putting locks everywhere often means you get a lot of locking overhead and sometimes so much lock contention that you don't really get the concurrency advantage you were hoping for. Even when you've got the locking right, you then need to profile to tune for cache coherency. Ultimately, if you want to really tune some highly concurrent code, you'll probably end up looking at lock-free constructs and more complex locking schemes than those in current multi-threading libraries.

Dickon Reed
A: 

Learn OpenMP and MPI for C and C++ code.

OpenMP also applies to other languages as well like Fortran I suppose.

Zan Lynx
A: 

Write smaller programs.

Other code languages/styles will let you do multithreading better (though multithreading is still really hard in any language) but the big benefit for regular developers, IMHO, is the ability to execute lots of smaller programs concurrently to accomplish some much larger task.

So, get in the habit of breaking your problems down into independent components that can be run whenever you want.

You'll build more maintainable software too.

James
+2  A: 
  • Prefer immutable data structures, their use makes software easier to understand not only in concurrent programs.

  • Learn the tools for concurrency in your language (e.g. java.util.concurrent, JCIP).

  • Learn a functional language (e.g Haskell).

starblue