954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

questions on multiple thread programming

I perhaps have to resort to multiple thread programming to reduce computational time. I am now studying how to use POSIX library.
I can access a cluster with 8 CPUs, each of which has one core. I was wondering how many threads to create would get approximately best time performance on my cluster? Is it the same number of CPUs? If I am using multiple thread library like POSIX, will the library take care of which thread run on which CPU or do I have to specify this in my code?

Thanks!

lehe
Light Poster
36 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

One program -- one computer -- one CPU. One program can not run across multiple computers like you describe. If the computer has multiple cores then the operating system might distribute the threads among the cores, but it will not distribute threads across computers. There might be special add-on kernel-level software that will facilitate that, but its not a native feature of most computers.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

if you have a very simple program that just has to run a zillion times, you can use OpenMP parallel for loops. You just put a #pragma right before the loop and it magically splits it across all available cores.

You can do more complicated things with openmp, but this is what I use it for.

Dave

daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
 

C++ doesn't provide built-in support for multithreading, the reason for that is you have to use the operating system's features to write a multithreaded application (as it's the most efficient way) ...

But as Ancient Dragon did already say: The Operating System has to distribute the threads among all the available CPU-cores ...

Maybe this article is useful for you ...

tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You