Major deviation from my original post
I realize that the long code I originally had was very discouraging to debug and did not attract any answers. So I have decided to revamp this question significantly (I hope this is acceptable). Please visit the edit history for older versions of this question.
Game Plan
I hypothesize that there are multiple errors in my script the is causing the kernel to crash. But since I can not identify them all at this time, I plan to identify one problem at a time, get solution, implement it in my code and repeat the process of identifying the next problem and posting it on this page, till all the issues are resolved.
Problem 1. The following code compiles fine:
a=Compile[{{p1,_Real,0},{p2,_Real,0}},Max[0.,Min[p1,10.]-p2],RuntimeAttributes->{Listable}];
b=Compile[{{p1,_Real,0},{p2,_Real,0},{p3,_Real,0},{p4,_Real,0}},
Max[0.,Min[(20.-p1) 5.-p2-p3,10.]-p4],RuntimeAttributes->{Listable}];
ab=Compile[{{p1,_Real,0},{p2,_Real,0},{p3,_Real,0},{p4,_Real,0},{p5,_Real,0}},
Min[a[p1,p5],b[p2,p3,p4,p5]],RuntimeAttributes->{Listable},
CompilationOptions->{"InlineExternalDefinitions"->True}];
f=Compile[{},Module[{k0=Table[0.,{10}]}, ab[k0,k0,k0,k0,k0]],CompilationTarget->"C",
CompilationOptions->{"InlineExternalDefinitions"->True}];
But when I execute f[]
, the kernel crashes. I am guessing, it is to do with mixing Scalars with Vectors in the a
and b
functions. But that is what I thought Listable
takes care of. Any thoughts?
MainEvaluate
compilation is of dubious use in any case, correct? Perhaps useful: Compiling more functions that don't call MainEvaluate./q/24595/131 $\endgroup$CompilationOptions -> {"InlineExternalDefinitions" -> True}
(2) Definef2[x1_Integer, x2_Integer, x3_Integer] := f[x1, x2, x3]
and usef2
in the call toNMinimize
. Not sure if these will help but they should at least keep the compiled code from calling on the main evaluator. $\endgroup$