LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reg. Constant folding of wires and structures settings.

Hi Hello,

 

Constant folding settings under options -> Block diagram.

 

what is this setting Constant Folding of wires and structure under constant folding?

 

0 Kudos
Message 1 of 17
(3,899 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 17
(3,870 Views)

@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.

(example)

0 Kudos
Message 3 of 17
(3,836 Views)

@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 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 17
(3,815 Views)

Also note that significant folding only occurs of you disable debugging. 

Message 5 of 17
(3,800 Views)

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...

0 Kudos
Message 6 of 17
(3,770 Views)

@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.

 

0 Kudos
Message 7 of 17
(3,732 Views)

Time for some examples to show what CA means:D

 

Fig 1 a new unsaved vi

Capture.png

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:

CaptureSave.PNG

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

CaptureDBDisSave.PNG

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)


"Should be" isn't "Is" -Jay
Message 8 of 17
(3,722 Views)

@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.

0 Kudos
Message 9 of 17
(3,713 Views)

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.

0 Kudos
Message 10 of 17
(3,689 Views)