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?
MainEvaluatecompilation is of dubious use in any case, correct? Perhaps useful: Compiling more functions that don't call MainEvaluate./q/24595/131 – Yves Klett Jun 11 '14 at 19:10CompilationOptions -> {"InlineExternalDefinitions" -> True}(2) Definef2[x1_Integer, x2_Integer, x3_Integer] := f[x1, x2, x3]and usef2in the call toNMinimize. Not sure if these will help but they should at least keep the compiled code from calling on the main evaluator. – Daniel Lichtblau Jun 11 '14 at 19:16f2[x1_Integer, x2_Integer, x3_Integer] := f[x1, x2, x3]withf2inNMinimizemakes it slower on my i5-3210 2.5GHz processor with 6 GB ram computer. without it, and only the code I shown above, it runs quicker. I am confused. With CompilationTarget->"C", the program executes, but does not produce any output (even though I havePrintin myEvaluationMonitor). You can try it too!! – brama Jun 12 '14 at 15:16Compileexecutes to completion. I useprintoutsidecompileand it prints it. However, it does not executeNMinimizeproperly and terminates without iterating even once. The program does not crash on my windows machine. – brama Jun 12 '14 at 15:40CopyTensorin the above code. Does it mean it holds memory till I close MMA and garbage collection does not kick in? Could this be the reason why the physical memory keeps increasing continuously as I run my program? – brama Jun 12 '14 at 15:52Whileloop, so yes, that could account for the memory issues. – Daniel Lichtblau Jun 12 '14 at 17:25CompilationTarget->“C”? Without it, it works, but when I use it in thecompile, thekernelis crashing withNMinimize. See @Dan's comments above. He also observed same behavior. – brama Jun 19 '14 at 01:31CompilationTarget -> "C". Just wanted to make sure: Did you use the above code "as is" or made any improvements? @Dan can you please check if this works for you? – brama Jun 19 '14 at 04:27CompilationTarget -> "C"made trouble, but I haven't yet managed to reproduce this kind of problem with a simple enough example for so long. – xzczd Jul 03 '14 at 08:23