Skip to content

Commit

Permalink
Added synchronous method to 1 million puzzle example
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinTSchaffer committed Mar 12, 2020
1 parent e7d9a1a commit 6c8df48
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions samples/1_million_puzzle_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ def solve_sudoku(input_data):
return (index, puzzle, state, completed_puzzle)

def main():
num_cores = multiprocessing.cpu_count()
pool = multiprocessing.Pool(num_cores - 2)

for index, puzzle, result, completed_puzzle in pool.imap_unordered(solve_sudoku, iterate_through_puzzles()):
print(f'Result {result} Puzzle Index: {index} Initial configuration: {puzzle}')
try:
num_cores = multiprocessing.cpu_count()
pool = multiprocessing.Pool(num_cores - 2)
run_in_parallel = True
except:
run_in_parallel = False

if run_in_parallel:
for index, puzzle, result, completed_puzzle in pool.imap_unordered(solve_sudoku, iterate_through_puzzles()):
print(f'Result {result} Puzzle Index: {index} Initial configuration: {puzzle}')
else:
for data in iterate_through_puzzles():
index, puzzle, result, completed_puzzle = solve_sudoku(data)
print(f'Result {result} Puzzle Index: {index} Initial configuration: {puzzle}')

print('Done')

Expand Down

0 comments on commit 6c8df48

Please sign in to comment.