SetEvaluationFlag
new to Analytica 4.6
SetEvaluationFlag( flag, enable, expr )
Sets or resets a flag that has some effect on how Analytica evaluates expressions, and then evaluates «expr» with the indicated flag value. The change takes effect only within the scope of «expr» -- after the function completes, the flag has its original value. This is used primarily for turning on or off certain speed optimizations in cases where those speed optimizations might interact in an undesirable manner with «expr».
The «flag» parameter may be one of the following values:
- "evaluationContext"
- "fastCOMcalls"
- "fastCOMproperties"
These are described in detail in the sections below.
To set a flag, pass True
for the «enable» parameter. To clear a flag, pass False
for «enable».
EvaluationContext
Suppose only one slice of an intermediate result will be retained in the final result. Analytica can reduce computation time by only computing the one slice.
The system variable EnableEvalContextUse controls whether this speed optimization is applied globally to the whole model. It is set to 1 by default. SetEvaluationFlag is used to override this global setting just while «expr» is evaluated.
There are a few potential reasons for disabling this speed optimization. Usually it will be because you have a legacy model that was created prior to Analytica 4.6 (when this speed optimization was introduced), and you find that this optimization changes or breaks something in your model. Hence, you can turn the feature off to retain backward compatibility. You might turn it off globally initially, but then later turn it back on globally and use SetEvaluationContext to turn it off only in specific places.
If a bug is discovered in the future (i.e., the optimization screws up something), SetEvaluationFlag will provide a way to work around it. Hopefully this won't happen.
Consider the expression, where A
and B
are both indexed by I
, an index with 10 elements.
Var count := 0; Var x[ ] := A; Var y[ ] := B+x; MsgBox( x & ',' & y ); count := count + 1; Uniform( x,y )
The declaration for x
specifies that it has no indexes, it is atomic, within the lexical context of x. Since A is indexed by I
, this requires the expression that follows to be evaluated 10 times, once for each atomic value of A. The same holds for y
. However, the evaluation context optimization allows Analytica to recognize that a second iteration over I
is unnecessary. Hence, the body needs to be evaluated only 10 times. When this completes, count will be 10.
Without the evaluation context optimization, two nested iterations occur. You'll see a MsgBox 100 times, count
will be 100 at the end, and Uniform will have been called 100 times. This illustrates three differences that the optimization can cause in legacy models: Side-effects in the form of interactions with the user may occur fewer times, side-effects in the form of variable assignments (count) may occur fewer times, and the number of calls to random number generation may occur fewer times, this altering the RandomSeed, which in turn will alter the random values sampled during Monte Carlo analysis.
Enable comment auto-refresher