Skip to main content

Assignment of Analytic Variable

Analytic variables are in common, global to the whole analytic, and therefore:

  • The expression as well as the variable index (if the variable is of type complex), MUST not reference any Element property or Element attribute. The reason for this is that it is not possible to know or define which element would be used, among those contained in the Working Space.

  • The assignment is executed only once, regardless of the number of elements of the Working Space. The reason for this is so that the same assignment is not repeated multiple times; which would not make sense.

Let's assume we want to totalize the reconciled mass of all elements in an analytic variable, without considering that the logic is executed in parallel for each element contained in the Working Space. The proper approach would be to declare an analytic variable and then add each o_Rec_Mass attribute value to it.

Assignment of Analytic Variable - example

As you can see, the example does not work. Since the variable is in common to the whole analytic, all the assignments are performed only once and do not allow the use of element properties or attribute values like the following:

  • Even if the assignments were performed for all the elements contained in the Working Space, the result would be unpredictable, as the additions would be performed in parallel (no thread safe).

  • Since assignments to Analytic Variables are performed outside the Working Space, the execution would produce an error as the o_rec_mass attribute would be unresolvable.

danger

Never use element attributes in the expression while assigning an analytic variable.

info

Remember that an analytic variable is assigned only once, regardless of the number of elements contained in the working space.

tip

For totalization, assignment purposes always use the proper InterlockedOperator built-in function designed to support parallel processing.

Always remember that assignments to Analytic variables do not support element attribute values and are executed only once, though the Working Space may contain several elements.