From the course: Parallel and Concurrent Programming with C++ Part 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Merge sort

Solution: Merge sort - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 2

Start my 1-month free trial

Solution: Merge sort

(upbeat music) - [Instructor] For our solution to the merge sort challenge, we used a recursive divide and conquer approach with multiple threads sorting subsections of the overall array. For the divide phase, rather than recursively subdividing the array until it reaches single elements, we've first configured our base case to subdivide the array based on the number of processors on the computer. For example, if the computer only had four processors, then it would only go through two layers of subdivisions to produce four subarrays in need of sorting. We then give each of the processors a separate thread executing the sequential_merge_sort algorithm to sort each subarray in place. And then the main processor merges the results back together as a recursion unwinds, and each of the other threads finishes sorting their subarrays. By limiting the depth of recursion in our base case, we're able to use a few threads to sort…

Contents