Im trying to compile the following function:
n := 5
fc = Compile[{{l,_Integer,1}},
a=1;b=1;
Do[
If[l[[i]]==1,
a=a+2b; b=b+i,
b=a+b; a=a+i],
{i,n}];
b,
RuntimeAttributes -> {Listable},
Parallelization -> True]
fc[Tuples[{0,1},n]]
However this gives the following errors:
CompiledFunction::pext: Instruction 1 in CompiledFunction[{10,11.2,5852},{{_Integer,1}},{{2,1,0},{2,0,1}},{{0,{2,0,2}},<<1>>,{1,{<<1>>}}},<<1>>,{{46,Function[{l},a=1],2,1,0,6,0,17},{46,Function[{l},b=1],2,1,0,6,0,17},{46,Function[{l},n],2,1,0,3,0,2},{40,50,3,0,2,2,0,1},<<10>>,{4,3,1,-8},{46,Function[{l},b],2,1,0,2,0,1},{1}},Function[{l},a=1;b=1;Do[If[l[[i]]==1,a=Plus[<<2>>];b=Plus[<<2>>],b=Plus[<<2>>];a=Plus[<<2>>]],{i,n}];b,Listable],Evaluate] calls ordinary code that can be evaluated on only one thread at a time.
and
CompiledFunction::cflist: Nontensor object generated; proceeding with uncompiled evaluation.
Additionally, the result is often wrong and inconsistent. It works correctly when Parallelization is turned off. Am I doing something wrong here or is there just something wrong with my setup?