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?


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.

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.


commented: Nice to know, I didn't know it ... +1
commented: Excellent :) +36

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 ...