The following is a simplified example. We construct a library function f and another library function g, in which the library function f is called.
f = Compile[x, Integrate[1 + t^2, {t, 0, x}], CompilationTarget -> "C"];
g = With[{f = f}, Compile[x, x + f[x], CompilationTarget -> "C"]];
CompilePrint shows the following for the function g:
1 R1 = LibraryFunction[<>, compiledFunction0, {{Real, 0, Constant}}, Real][ R0]]
2 R2 = R0 + R1
3 Return
Now we test the functions f and g on the main kernel and on two subkernels:
LaunchKernels[];
DistributeDefinitions[f,g];
f[2.3]
g[1.2]
ParallelEvaluate[f[2.3], 1]
ParallelEvaluate[g[1.2], 1]
ParallelEvaluate[g[1.2], 2]
(* Out[7]= 6.35567
Out[8]= 2.976
Out[9]= 6.35567
Out[10]= 2.976
During evaluation of In[5]:= LinkObject::linkd: Unable to communicate with closed link LinkObject["C:\Program Files\Wolfram Research\Mathematica\10.0\MathKernel" -subkernel -noinit -mathlink -noicon,225,5]. >>
During evaluation of In[5]:= KernelObject::rdead: Subkernel connected through KernelObject[2,local] appears dead. >>
Out[11]= $Failed *)
The evaluations on the main kernel and on subkernel 1 are fast. On subkernel 1 we first evaluated f and next g. On subkernel 2 we immediately called g, without having used f before. The subkernel crashes. I am running Mathematica 10.0.2 32 bits on Windows 7.
CompilePrint[f]
? The presence ofIntegrate
means it just callsMainEvaluate
. Your simplified example may well need changing... $\endgroup$With
, can you tryCompilationOptions -> {"InlineCompiledFunctions" -> True}
for your functiong
? $\endgroup$