-
-
Notifications
You must be signed in to change notification settings - Fork 46.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd-Even Transposition Sort #769
Conversation
This is a modified bubble sort meant to work with multiple processors. Since this is running on a single thread, it has the same running time as bubble sort.
This implementation uses multiprocessing to perform the swaps at each step of the algorithm simultaneously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pull request!🤩
@CharlesRitter
|
from multiprocessing import Process, Pipe, Lock | ||
|
||
#lock used to ensure that two processes do not access a pipe at the same time | ||
processLock = Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss We can use the spawn
method to start the subprocess. The spawn
method is considered safer than the fork
method. We will get a warning for the fork
method in Python 3.12+.
from multiprocessing import Process, Pipe, Lock | |
#lock used to ensure that two processes do not access a pipe at the same time | |
processLock = Lock() | |
from multiprocessing import Process, Pipe, Lock, set_start_method | |
set_start_method("spawn", force=True) # set the start method before using the context in `Lock()` below | |
#lock used to ensure that two processes do not access a pipe at the same time | |
processLock = Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Can you please make this a pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a PR to resolve this.
Here are single and multi-threaded implementations of Odd-Even transposition sort.
It is an O(n) sorting algorithm that performs its swaps simultaneously.
https://en.wikipedia.org/wiki/Odd%E2%80%93even_sort