I am creating an algorithm that brute force searches for conditions of a 3x3 matrix using a generator object to create all possible combinations. Currently, the amount of time needed to run it on a single thread would take a massive amount of time, however I have access to a computer with many cores (64), so threading it to have at least 20 threads would be a very viable option.
However, I cannot simply convert the generator object to a list and split the list up into equal sized chunks. The amount of RAM required to store the list of lists is far too high.
My single threaded approach (simplified for the question) is as follows:
def permute(xs, low=0):
if low + 1 >= len(xs):
yield xs
else:
for p in permute(xs, low + 1):
yield p
for i in range(low + 1, len(xs)):
xs[low], xs[i] = xs[i], xs[low]
for p in permute(xs, low + 1):
yield p
xs[low], xs[i] = xs[i], xs[low]
generator_obj = permute(range(9))
for l in generator_obj:
search_conditions(l)
What would be a good approach to threading this?