If a global variable is changed before each call of the function then answer is not changed accordingly. Please see a toy example:
Clear[zIc];
With[{Aopt = Aopt},
zIc = Compile[{{q, _Integer}},
Aopt + q
, CompilationTarget -> "C",
CompilationOptions -> {"InlineExternalDefinitions" -> True}
]];
Aopt = 1;
zIc[3]
Aopt = 3;
zIc[3]
(Debug) Out[203]=
6
(Debug) Out[205]=
6
Expected answers are 4
and 6
. I familiar with 31627 and 78768 posts but theirs solutions don't help.
[EDITED]:
- Removing
With
doesn't help also. - As it is very simple toy example it seems to be very obvious answer to pass global variable as an argument to the function but not in real code where
zIc
already has 7 arguments andAopt
is calculated 4 logical layers above.
C
, but it won't really give you tangible benefits. $\endgroup$"InlineExternalDefinitions"
option (which essentially bakes the current value ofAopt
into the function). $\endgroup$