Review/my mergesort bunsarak#2
Open
Bunsarak27 wants to merge 8 commits into
Open
Conversation
Includes a partially-authored README file. However, there are still some changes to make, as there are sections which we cannot fill out yet. This commit was accidentally authored under my university GitHub identity, woops. --------- Co-authored-by: Izak Baldacchino <a1830164@student.adelaide.edu.au>
Follows the basic mergesort algorithm provided by the video shown on the assignment description. Other sources accessed include: cppreference.com (for memcpy).
Includes a Makefile based on a template I created for an old project (which can be found here: github.com/Izak8/gl). Build flags differ from original assignment; changed C standard from gnu89 to c11. gnu89 seems unecessarily limiting.
Just simply uses scopes to create predictable conditions. If the test executable isn't aborted by a failed assertion, then it is considered to pass.
…hat still has elements.Finish with a single memcpy from B[left..right] back to A had to remove <error.h> include so tests build locally
…hat still has elements.Finish with a single memcpy from B[left..right] back to A had to remove <error.h> include so tests build locally
…el_mergesort, No threading changes yet; parallel_mergesort() remains a stub,fix(sort): correct my_mergesort base case (use left >= right)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does not change threading yet; it just ensures the sequential path is correct, and ready to be called when we stop spawning threads at the cutoff. What I changed
Added a recursive my_mergesort(int left, int right):
Base case: if (left >= right) return; (0 or 1 elementalready sorted).
Compute mid = left + (right - left)/2 (overflow).
Recurse on [left..mid] and [mid+1..right].
Call merge(left, mid, mid+1, right) to combine the two sorted halves.
This will ct as the fallback when the cutoff level is reached in the parallel version, and provide a baseline to compare speedups when we add threads later on. Issues I hit (and how I resolved them) i use a mac so, MacOS <error.h>: some forks include #include <error.h> (GNU extension). On macOS this header doesn’t exist; removing that include lets clang compile. i accidentally write if (left <= right) return;. Fixed to left >= right so we stop when the range has ≤1 element.
References: https://www.youtube.com/watch?v=b1n9T-Iy3SA
Operating Systems: Three Easy Pieces (Arpaci-Dusseau & Arpaci-Dusseau):
Standard mergesort recurrence and merge-procedure patterns (CLRS-style).