pthreads slowdown

Hi All,

I am using four pthreads for my branch and bound implementation but surprisingly I am getting a 2X SLOWDOWN as a result!

Parallelizing a tree search algorithm to four threads should surely have some kind of improvement..

It is my first time using pthreads, I was wondering if i am missing anything or if I have something wrong or missing, I have the linking option -lpthreads in my makefile too. Here's the threading part of my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    rc = pthread_create(&thread_one, NULL, TaskCode, (void *) &thread_one_args);
    assert(rc==0);
    rc = pthread_create(&thread_two, NULL, TaskCode, (void *) &thread_two_args);
    assert(rc==0);
    rc = pthread_create(&thread_three, NULL, TaskCode, (void *) &thread_three_args);
    assert(rc==0);
    rc = pthread_create(&thread_four, NULL, TaskCode, (void *) &thread_four_args);
    assert(rc==0);

    rc = pthread_join(thread_one, NULL);
    assert(0 == rc);
    rc = pthread_join(thread_two, NULL);
    assert(0 == rc);
    rc = pthread_join(thread_three, NULL);
    assert(0 == rc);
    rc = pthread_join(thread_four, NULL);
    assert(0 == rc);
Last edited on
Nothing that's obvious from what you've posted.
Is this running in a loop? Does TaskCode run for a significant amount of time? It could be that more time is being spent creating and waiting for threads than performing useful work.
Is this running in a loop? Does TaskCode run for a significant amount of time?


without threads it takes 40 seconds
with threads it takes 80 seconds

yes, it has a big loop which does graph depth-first traversal for a significant amount of time..
Topic archived. No new replies allowed.