09-29-2017 06:49 AM
Hi Hello,
Constant folding settings under options -> Block diagram.
what is this setting Constant Folding of wires and structure under constant folding?
09-29-2017 07:25 AM
Constant Folding is a compiler optimization where it can reduce parts of your code down to just a constant value. This happens regardless of those option settings. Those options just add little hashes to the artwork on the diagram to show where this constant folding is happening.
09-29-2017 11:51 AM
@LV_COder wrote:
Hi Hello,
Constant folding settings under options -> Block diagram?
As a first step, click on the help button. As a second step, do a Google search of the term. There is plenty of information out there.
09-29-2017 02:17 PM
@crossrulz wrote:
Constant Folding is a compiler optimization where it can reduce parts of your code down to just a constant value. This happens regardless of those option settings. Those options just add little hashes to the artwork on the diagram to show where this constant folding is happening.
Exactly.
When that settings is enabled, it shows you were the code is being "folded" into a constant. That option is very helpful when we are putting together benchmarking code and lets us know that the folded code is not going to be using CPU time when you code runs since the answer is always the same.
Ben
09-29-2017 03:34 PM
Also note that significant folding only occurs of you disable debugging.
09-30-2017 12:22 PM
And note that it's a subtle change. If you're new to LabVIEW, you might not notice it. And depending on your screen, it might be hard to see even if you know what to look for...
10-03-2017 11:07 AM
@altenbach wrote:
Also note that significant folding only occurs of you disable debugging.
Do you mean constant folding will be perform by the compiler only if debugging is disable.
Or
just disable the debugging to see the change (fuzzy wires and structure ) on the block diagram.
10-03-2017 11:28 AM - edited 10-03-2017 11:33 AM
Time for some examples to show what CA means:D
Fig 1 a new unsaved vi
It is reasonable to assume that "Array" will be 10 elements of integers 0, 1...9 no mater how many times it is run.
Saving the vi with default settings (Debugging enabled) yields this:
Notice the slight "~~~" wiggle on the wire from the constant 10? Yup- that's a 10 and a constant! The compiler will replace that 10 with a constant 10 in the compiled code. (OK, This is a simple example but imagine if we had a whole lot of convoluted R-G code that generated a 10 if a condition was true and a 10 if the same condition was false- the wiggle would be a nice tip that we need to post our code on breakpoint )
Pseudo Code:
If Condition
Value == 10
Else
Value ==10;
But, since debugging is enabled we could place a probe on the index scalar and highlight execution expecting the value to update during execution. So, we HAVE TO run the code and generate the array values. HOWEVER, if we disable debugging and save. we see this
The "///" slashes through the for loop show us the compiled code has pre-calculate "Array" and the code here is replaced by a "Folded" Constant. to make it faster (Optimized)
10-03-2017 11:39 AM
@LV_COder wrote:
Do you mean constant folding will be perform by the compiler only if debugging is disable.
Yes. This was not always handled the same in earlier versions, but in recent LabVIEW versions enabling debugging will limit folding to allow you to probe and debug the potentially folded code.
10-04-2017 02:49 AM
Turning it on sometimes doesn't seem to be enough to turn it on though.
I've no use for turning it on, I know when things are folded. I just wanted to test if LV13 did constant folding even when debugging was on. I do recall folding happening with debugging on.
However, turning it on didn't turn it on. I don't think a restart is required, and I had it turned on before. But when it's off, turning it on will definitely not always turn the feature on immediately. Not sure what trigger is needed, I do recall this from the past. You need to turn it on, and you don't see anything. so you give up, and at some point it is on.