![]() ![]() ![]() list ( 6 )) > a2 = Permutation ( Cycle ( 1, 2, 3 )( 5 )) > a3 = Permutation ( Cycle ( 1, 2, 3 ), size = 6 ) > for p in : p, G. This is a complete working script for Python 3 that summarizes everything: import itertoolsįor tail in itertools.permutations(remaining_chars, 3)]Īll_strings = pool.> from sympy import init_printing > init_printing ( perm_cyclic = True, pretty_print = False ) > from binatorics import Cycle, Permutation > from _groups import PermutationGroup > G = PermutationGroup ( Cycle ( 2, 3 )( 4, 5 ), Cycle ( 1, 2, 3, 4, 5 )) > p1 = Permutation ( Cycle ( 2, 5, 3 )) > p2 = Permutation ( Cycle ( 1, 2, 3 )) > a1 = Permutation ( Cycle ( 1, 2, 3 ). Since 26 is an odd number for 16 cores, we could think about creating the heads with itertools.permutation(remaining_chars, 2) and then using the set subtraction to generate the last 6 digits. Once that is finished the flatten the list of lists into a plain list of strings: strings = [ The pool only got the needed _enter_ and _exit_ properties with Python 3, so I assume that we use that. Now somewhere else we can create a pool and let it map over heads: with multiprocessing.Pool() as pool:Īll_strings = pool.map(make_strings, chars) This is just the above a bit refactored: def make_strings(head):įor tail in itertools.permutations(remaining_chars, 7)] ![]() For this we first need a function to map over. In order to make use of multiple cores, we use a pool. This exact loop will beįor tail in itertools.permutations(remaining_chars, 7): # We iterate through all the possible heads. This could look like this: # Use whatever chars you want as the set. This way we can have 26 tasks (or 52 or 62) and still use the algorithm. With that idea in mind, we can do better! We parallelize on the first letter of the string and then generate all permutations with seven elements from the set excluding the letter that we started with. But when you want to pick 25 from 26 letters, this becomes really wasteful. If one only wants to pick 8 letters from a set of 26, 52 and 62, one could do a naive brute thing: Parallelize on the first letter, let the thread just create the tail with replacement and discard the generated strings that contain duplicates. You want to have a permutation without replacement, so the problem does not trivially factorize. If that is not enough, you could parallelize on the first two letters. This would give you 26 independent tasks. If it were just permutations with replacement, it would be very easy: Just parallelize on the first letter of the string and then let each thread add the tail of the string. If I can partition it up into 16 tasks, and run on 16 Xeon CPUs, then join the results, that would be great. I might just try a (possibly) faster way of doing it, but I'm having trouble with C++ and its std::next_permutation(), so I can't verify that it could speed things up even a little just yet. My problem is that I don't understand the underlying algorithm and so I can't begin to figure out if I can split the problem up into smaller tasks than I can join together later.Ī python script I was using to generate a list of permutations: import stringĬomb = itertools.permutations(string.ascii_lowercase, 8)ĭoes anyone know how to partition this up into subtasks and put them together later? Is it possible at all? Which I know will quickly take a great deal of time and space.Įven just a permutation of length 8 from the lowercase ASCII characters takes a while and generates gigabytes. ![]() Specifically I'm using 8 out of and I'd like to use 8 out of and 8 out of. I'm trying to figure out if I can speed up the generation of permutations. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |