When you pack lists there is an overhead therefore packing a list with, say, 2 elements is likely to cost more than you get back in efficiency. Mathematica has default list lengths for which functions creating those lists will pack the list (i.e. if the list length is less than the numbers shown below the list will not be packed):
SystemOptions["CompileOptions"]
{"CompileOptions" -> {"ApplyCompileLength" -> \[Infinity],
"ArrayCompileLength" -> 250, "AutoCompileAllowCoercion" -> False,
"AutoCompileProtectValues" -> False, "AutomaticCompile" -> False,
"BinaryTensorArithmetic" -> False, "CompileAllowCoercion" -> True,
"CompileConfirmInitializedVariables" -> True,
"CompiledFunctionArgumentCoercionTolerance" -> 2.10721,
"CompiledFunctionMaxFailures" -> 3,
"CompileDynamicScoping" -> False,
"CompileEvaluateConstants" -> True,
"CompileOptimizeRegisters" -> False,
"CompileReportCoercion" -> False, "CompileReportExternal" -> False,
"CompileReportFailure" -> False, "CompileValuesLast" -> True,
"FoldCompileLength" -> 100, "InternalCompileMessages" -> False,
"ListableFunctionCompileLength" -> 250, "MapCompileLength" -> 100,
"NestCompileLength" -> 100, "NumericalAllowExternal" -> False,
"ProductCompileLength" -> 250, "ReuseTensorRegisters" -> True,
"SumCompileLength" -> 250, "SystemCompileOptimizations" -> All,
"TableCompileLength" -> 250}}
So, for example, if you make a list using Table
Developer`PackedArrayQ[Table[i, {i, 1, 249}]]
False
Developer`PackedArrayQ[Table[i, {i, 1, 251}]]
True
I am assuming that if you plotted the time to make uncompiled lists using Table
, vs making compiled lists, the lines would intersect at ~250, beyond which packed lists become more efficient. Is that a correct interpetation of what the autocompilation length represents?
I would expect that the optimal lengths for compilation (incl. packing) vary on system to system, therefore I want to know the best way to construct a set of tests to test that proposition, and to determine the optimal list length for packing for the functions listed above.
Edit
For clarity, as per Albert's comments, there are cases when the evaluations taking place prevent compilation so these discussions are redundant, i.e. compilation is prevented regardless of the default settings. But I am curious about the optimal list lengths in cases where compilation occurs.
Comments
Post a Comment