Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parallel-ize an algorithm on a machine with multiple processors?

  • Intel Core2Duo, for example is supposed to have a single die but two cores.

  • So, it should be possible to control what is processed on which core, which means that it is possible to instruct my algorithm to use the two cores in parallel.

The question is how?

Do I need to go down at the kernel level to do this, or is there a simpler way? To be more concrete, what does it take to implement a dual-core-merge-sort?

like image 232
Lazer Avatar asked Aug 27 '10 19:08

Lazer


1 Answers

Judging by your past questions, I'd say you're looking to implement in C/C++, but I believe the answer is roughly the same regardless of language.

If you want to parallelize any operation, make it multithreaded. You can have as many parallel, concurrent threads as you have cores.

Here's a related question: How to implement divide and conquer algorithms in C# using multithreading?

As I understand it, binding a particular thread to a core or processor is called processor affinity. It's generally not a good idea, because the purpose of the operating system is to juggle threads between processors. It's unlikely that you'll do a better job of this than the OS can.

like image 177
Dave Swersky Avatar answered Sep 24 '22 13:09

Dave Swersky