Compile

*To*: mathgroup at smc.vnet.net*Subject*: [mg86001] Compile*From*: "Michael Weyrauch" <michael.weyrauch at gmx.de>*Date*: Sat, 1 Mar 2008 04:42:23 -0500 (EST)

Hello, in Mathematica V6.0.1 I define the following two functions multiset[n_] := Module[{ro, re, ms}, ro = Range[1, 2*n, 2]; re = Range[2, 2*n, 2]; ms = Flatten[Table[{i, i}, {i, n}]]; Select[Permutations[ms], ! MemberQ[Sign[#1[[re]] - #1[[ro]]], -1] & ]] multisetC = Compile[{{n, _Integer}}, Module[{ro, re, ms}, ro = Range[1, 2*n, 2]; re = Range[2, 2*n, 2]; ms = Flatten[Table[{i, i}, {i, n}]]; Select[Permutations[ms], ! MemberQ[Sign[#1[[re]] - #1[[ro]]], -1] & ]]]; Obviously, multisetC ist just the compiled version of multiset. Now, I evaluate Timing[Length[multiset[5]]] Timing[Length[multisetC[5]]] and obtain {2.7339999999999995, 6210} {0.3440000000000003, 6210} so Compile was really useful. However, if I evaluate Timing[Length[multiset[6]]] Timing[Length[multisetC[6]]] {189.109, 202410} No more memory available. Mathematica kernel has shut down. So, the compiled version fails badly and crashes the kernel. This also happens if I evaluate this statement seperately in a completely fresh kernel. Enough memory is definitly available, since the uncompiled version runs smoothly. (Surprisingly the crash is immediate, not after some time of working along in the program, and it happens on Windows with 2GB of memory and on Linux with 32 GB of memory.] It would be nice if some could explain this unpleasant behaviour. Is there a fix or is it a bug? Michael Weyrauch