Skip to content
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

Merged
merged 2 commits into from
Jun 7, 2019
Merged

Conversation

CharlesRitter
Copy link
Contributor

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

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
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.
Copy link
Member

@poyea poyea left a 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!🤩

@poyea poyea merged commit 6e894ba into TheAlgorithms:master Jun 7, 2019
@cclauss
Copy link
Member

cclauss commented May 1, 2024

@CharlesRitter
On our GitHub Actions tests, we are getting these 45 warnings. Do you know how to fix them?

sorts/odd_even_transposition_parallel.py: 45 warnings
  /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/multiprocessing/popen_fork.py:66:
   DeprecationWarning: This process (pid=1839) is multi-threaded, use of fork() may lead to deadlocks in the child.
    self.pid = os.fork()

@cclauss cclauss added help wanted awaiting changes A maintainer has requested changes to this PR labels May 1, 2024
Comment on lines +13 to +16
from multiprocessing import Process, Pipe, Lock

#lock used to ensure that two processes do not access a pipe at the same time
processLock = Lock()
Copy link
Contributor

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+.

Suggested change
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()

Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes A maintainer has requested changes to this PR help wanted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants