Question

I work with a virtual machine computer cluster with many amd64 processors and Debian Squeeze. Previously, I've successfully executed shell scripts in parallel on it (with GNU Parallel). Now, I'd like to use boost::threads. I run this program:

#include <boost/thread.hpp>

using namespace std;
boost::thread_group g;

void foo()
{
    for(int i = 0; i < 1000000000; ++i) 
        for(int i = 0; i < 1000000000; ++i);
}

int main(int argc, char* argv[])
{
    g.add_thread(new boost::thread(foo));
    g.add_thread(new boost::thread(foo));
    g.add_thread(new boost::thread(foo));

    g.join_all();
}

All these threads run on a single processor, that is used in 300% (according to top command). How to make these three threads to run on three separate processors? Is it possible with boost::threads?

Note: This Multiprocessor Boost::Thread? All threads running on one processor, despite the title, is about multicore system whereas mine is truly about multiprocessor system.

Was it helpful?

Solution

It's running correctly. You're spawning three threads and all three are running concurrently. The reported CPU usage in multi-threaded applications is the sum of the CPU usage of all the threads. You have three threads that each use 100%, therefore you have 300% usage.

Multiple cores and multiple CPU sockets appear the same in nearly all threading libraries. You have to go out of your way to tell the difference, eg. libNUMA.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top