3
$\begingroup$

I have this code to find all the permutations of a set of letters that form legal words.

<<Combinatorica`
Module[{str = "abc", chars, len, r, check},
 chars = Characters[str];
 len = StringLength[str];
 r = Range[len];
 check[n_Integer] := 
  DictionaryLookup[{"BritishEnglish", 
    StringJoin[chars[[UnrankPermutation[n, r]]]]}, 1];
 DistributeDefinitions[check, chars, r];
 ParallelTable[check[i], {i, 1, len!}]]

I've verified that, if I replace ParallelTable with Table, I get this:

{{}, {}, {}, {"cab"}, {}, {}}

With ParallelTable, however, in addition to that result, I also get warnings like these:

Part::pspec: Part specification Combinatorica`UnrankPermutation[1,{1,2,3}] is neither a machine-sized integer nor a list of machine-sized integers.

Part::pspec: Part specification Combinatorica`UnrankPermutation[2,{1,2,3}] is neither a machine-sized integer nor a list of machine-sized integers.

StringJoin::string: String expected at position 1 in StringJoin[{a,b,c}[[Combinatorica`UnrankPermutation[1,{1,2,3}]]]].

StringJoin::string: String expected at position 1 in StringJoin[{a,b,c}[[Combinatorica`UnrankPermutation[2,{1,2,3}]]]].

These warnings seem to come from kernel 7 and higher. My guess is that the computation reaches those kernels and there isn't any data left, since there are only 6 permutations, and causes them to spit out those warnings.

Is my understanding correct? How do I prevent these warnings?

$\endgroup$
1
  • $\begingroup$ I think >> should be <<. $\endgroup$
    – Michael E2
    Commented Mar 14, 2013 at 14:28

1 Answer 1

2
$\begingroup$

Add UnrankPermutation to DistributeDefinitions:

DistributeDefinitions[check, chars, r, UnrankPermutation];
$\endgroup$
3
  • $\begingroup$ Is this because UnrankPermutation comes from the Combinatorica package and isn't a built-in? $\endgroup$
    – Ashley
    Commented Mar 14, 2013 at 15:41
  • $\begingroup$ Yes. Using Get (<<) loads the definitions in the Combinatorica package. Any you want to use in parallel should have their definitions distributed. $\endgroup$
    – Michael E2
    Commented Mar 14, 2013 at 15:53
  • 3
    $\begingroup$ Better use ParallelNeeds["Combinatorica`"]. $\endgroup$ Commented Mar 14, 2013 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.