omp parallel for loop, on map stl c++

General OpenMP discussion

omp parallel for loop, on map stl c++

Postby open_coder » Tue Oct 30, 2018 12:20 am

i am trying to apply parallel weight updation in dijsktra algorithms, when a node is choosen as min, update its all neighbours weight in parallel.

But with increasing threads cause increase in execution time, instead of decrease in execution time.
what is wrong in my code ?

##############################################################################################

omp_set_num_threads(2);
#pragma omp parallel private (my_first, my_last, i) shared(size, nth, my_id)
{
my_id = omp_get_thread_num();
nth = omp_get_num_threads();
size = ptr.size();

my_first = my_id*size / nth;
my_last = (my_id+1)*size / nth - 1;

#pragma omp critical
{
for(i=my_first; i<= my_last; i++){
p = ptr.begin();
advance(p,i);
if (mind[p->first] > md + p->second){
mind[p->first] = md + p->second;
Q.push(make_pair(mind[p->first], p->first) );
}
}
}
open_coder
 
Posts: 9
Joined: Mon Oct 29, 2018 9:42 pm

Re: omp parallel for loop, on map stl c++

Postby MarkB » Tue Oct 30, 2018 3:28 am

Almost all the work is inside the critical section, which only one thread at a time will execute, so you won't see any speedup.
What are you using the measure the execution time?
MarkB
 
Posts: 776
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: omp parallel for loop, on map stl c++

Postby open_coder » Tue Oct 30, 2018 5:25 am

I am using "time" linux command to measure execution time of my program.
open_coder
 
Posts: 9
Joined: Mon Oct 29, 2018 9:42 pm

Re: omp parallel for loop, on map stl c++

Postby open_coder » Tue Oct 30, 2018 5:56 am

Could any one suggest me how i can update map in parallel to speedup execution of my algorithm.
open_coder
 
Posts: 9
Joined: Mon Oct 29, 2018 9:42 pm

Re: omp parallel for loop, on map stl c++

Postby Oldboy » Wed Nov 07, 2018 12:30 pm

Take a look at this code:
http://people.sc.fsu.edu/~jburkardt/c_s ... a_openmp.c
It is very hard to win anything with few nodes (in this case 6).
Even with 60 nodes the open mp effect is small.
Oldboy
 
Posts: 25
Joined: Wed Oct 31, 2012 2:39 am

Re: omp parallel for loop, on map stl c++

Postby open_coder » Tue Nov 13, 2018 12:15 am

Can i do implement distributed heap in Dijkstra algorithms to speed up in find min element among all nodes.
open_coder
 
Posts: 9
Joined: Mon Oct 29, 2018 9:42 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Majestic-12 [Bot] and 5 guests

cron