Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sorts/odd_even_transposition_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ def oe_process(
rr_cv,
result_pipe,
multiprocessing_context,
phases: int,
) -> None:
process_lock = multiprocessing_context.Lock()

# we perform n swaps since after n swaps we know we are sorted
# we *could* stop early if we are sorted already, but it takes as long to
# find out we are sorted as it does to sort the list with this algorithm
for i in range(10):
for i in range(phases):
if (i + position) % 2 == 0 and r_send is not None:
# send your value to your right neighbor
with process_lock:
Expand Down Expand Up @@ -124,6 +125,7 @@ def odd_even_transposition(arr):
temp_rr,
result_pipe[0],
multiprocessing_context,
len(arr),
),
)
)
Expand All @@ -145,6 +147,7 @@ def odd_even_transposition(arr):
temp_rr,
result_pipe[i],
multiprocessing_context,
len(arr),
),
)
)
Expand All @@ -163,6 +166,7 @@ def odd_even_transposition(arr):
None,
result_pipe[len(arr) - 1],
multiprocessing_context,
len(arr),
),
)
)
Expand Down
Loading