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 - C++ Tutorial
From the course: Parallel and Concurrent Programming with C++ Part 2
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.