Reputation: 2471
I am trying to implement a parallel quick sort algorithm but i am not so sure how to make use of pthreads inside the quick sort function. This is a link to my code on paste bin http://pastebin.com/tG0h6cMU
Upvotes: 2
Views: 1707
Reputation: 23550
In general you could do without pthread_mutex_lock
, a parallel quicksort without thread-synchronization. According to WP: https://en.wikipedia.org/wiki/Quicksort#Parallelization
Now specifically to your implementation:
I cannot compile the code because i am missing read_in and gen_random but i can tell you these:
There are a few problems with your code:
Line 45: You are assigning an int r
to int* r
!!!
Line 133: if(a,...)
.
Also there are a few unused variables (237: unsorted, 236: sorted, 218: i). Maybe you forgot something
Upvotes: 0
Reputation: 129374
Number of threads per process should be near 1.0 if they are CPU bound. If there is I/O of some sort involved, then you can have more threads - for example, compiling the Linux kernel tends to run fastest if you run about 1.5 "jobs" (make -j N
where N = cores * 1.5) per core. Note however that this is very dependant on the actual behaviour of the threads/processes, and it's almost certainly necessary to measure the ideal performance for YOUR particular scenario.
Certainly, if the number of thread exceed the number of cores by too much, you get "thread thrashing". If there aren't enough threads, the cores aren't kept busy, so that's not great either.
Upvotes: 1