The performance of two threads is worse than a single thread

General OpenMP discussion

The performance of two threads is worse than a single thread

Postby freesummer » Thu May 03, 2018 9:41 am

In my code, I have two independent functions to implement search operation on two different data structure separately. One is a tree data structure, the other one is a hashmap data structure. So there is no data sharing between these two functions.
I was trying to execute the two search functions in parallel, so I used #pragma omp parallel section clause to implement it.
The code is below:
===================
matchResult result_t;
matchResult_H result_h; /* these are the two search result for the two data structures
/* tree_search( ) and hm_find( ) are the two search functions /*
#pragma omp parallel sections num_threads(2)
{
#pragma omp section
{
result_t = tree_search(tree2, arry1[ss]);
}
#pragma omp section
{
result_h = hm_find(map_PRQ, s[ss].key, s[ss].value);
}
}
int rst_b;
rst_b = match_func(result_t.match, result_h.match);
===================
For my understanding, the execution time of the two threads should equal to the larger time between the two search functions.
The only thing I am not sure is that the overhead for using OpenMP.
Since the two functions don't share memory, which means there should not have synchronization overhead.
However, the two threads' performance is about 5x worse than the single thread.
BTW: I use omp_get_wtime() to capture the execution time.
I would appreciate if someone could give me some hints to solve this problem.
freesummer
 
Posts: 3
Joined: Tue May 01, 2018 7:54 am

Re: The performance of two threads is worse than a single th

Postby MarkB » Tue May 15, 2018 7:27 am

How long does the code execute for one thread? What platform are you running on?
MarkB
 
Posts: 768
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: The performance of two threads is worse than a single th

Postby freesummer » Wed May 23, 2018 9:18 am

MarkB wrote:How long does the code execute for one thread? What platform are you running on?

Hi Mark,
The time_elapsed_in_seconds for one thread = 0.105982.
The platform I am running on is: Linux ubuntu 4.4.0-124-generic #148-Ubuntu SMP Wed May 2 13:00:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux.
freesummer
 
Posts: 3
Joined: Tue May 01, 2018 7:54 am

Re: The performance of two threads is worse than a single th

Postby MarkB » Thu May 24, 2018 5:16 am

freesummer wrote:The time_elapsed_in_seconds for one thread = 0.105982.


Is there one instance of the code in the parallel region or is it executed many times? And are you measuring the time for the parallel region or for the whole code?
MarkB
 
Posts: 768
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: The performance of two threads is worse than a single th

Postby freesummer » Thu May 31, 2018 5:26 am

Mark, thanks for your reply. I really appreciate it.
=============
The OpenMP code is in a while loop, so it will be executed many times (The number of executions depends on whether the input data satisfy the condition).
I am measuring the time for the whole code.
I am expecting that the time cost of using OpenMP should be less than the one does not use OpenMP.
freesummer
 
Posts: 3
Joined: Tue May 01, 2018 7:54 am

Re: The performance of two threads is worse than a single th

Postby MarkB » Sun Jun 03, 2018 10:39 pm

The overhead of a parallel region is typically a few microseconds to a few tens of microseconds. If the average sequential execution time of the code inside the parallel region is less than this, you will see slowdown.
MarkB
 
Posts: 768
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 5 guests

cron