def generate_matrix(q, number_processes = 35): field = Field(q) two_powers = [2 ** (q - i) for i in xrange(q + 1)] with Manager() as manager: A = manager.dict() # where we store the row integers amount = lambda : len(A) # I use this to print out how many rows we have generated periodically def append(x): if x in A: return 0 A[x] = True return 1 #append = lambda x : A.__setitem__(x, True) is_new = lambda x : not A.__contains__(x) # to avoid duplicate entries # we don't need the a = 0, b = q - 1 case because it requires setting the 0th column (0 * (q-1)) which has already been chosen a = q - 1 # generate all the numerators quickly numerators = [[field.add(field.multiply(a, t), c) for t in field.trace()] for c in field] bs = range(q - 3) + [q - 1] # all the b values we need _distribute(lambda bs : _make_and_start_process(bs, a, field, numerators, append, is_new, two_powers, amount), bs, number_processes) # start all the processes and then wait for them to finish # the keys of the dictionary represent the row integers for the problem return A.keys()