08-28-2013
04:59 PM
- last edited on
05-02-2025
07:50 PM
by
Content Cleaner
i don't understand ...
"constant folding of structures" seems not to work with LV 2013.
run the vi : ok
save the vi : ok
don't make an edit : ok
but i see no hash marks inside the for loop ?
like this : ( http://zone.ni.com/devzone/cda/pub/p/id/347 )
Where is the mistake ?
Thanks to all.
08-28-2013
07:05 PM
- last edited on
05-02-2025
07:50 PM
by
Content Cleaner
In the 2012 help it says: "LabVIEW does not constant fold structures if you enable debugging."
Oh, 2013, too:
LabVIEW uses constant folding to optimize the performance of VIs. With constant folding, LabVIEW computes constant values on first run of the VI, instead of calculating them during each run.
Note If you enable debugging, LabVIEW does not use constant folding for structures. |
Source:
https://www.ni.com/docs/en-US/bundle/labview/page/block-diagram-objects.html
08-29-2013 01:56 AM
The reason why structures cannot be folded as long as debugging is enabled is simple:
Constant folding replaces code in the compiled version of the VI with constants (hence the name). That means that a complete structure would be replaced with a single constant for the compiled code.
If debugging is enabled, it is possible (though maybe not likely) that the user wants to set a break point into that structure or use highlight execution to observe the execution of it. If the structure would have been replaced, that would not be possible....
The for loop with auto-indexing output of the iterator is the best example:
Using a constant for N, the loop can be replaced with an array constant of {0, 1, 2, ..., N-1}. But only as long as debugging is disabled.
If enabling debugging, highlight execution has to display the execution of the loop, so it must not be replaced.
Another option for NO constant folding of for loops like above is to use a computation (depending on values not known during compilation) or control to define N. The reason is that the length of the array is not known during compile time so no constant can be created for it....
hope this helps,
Norbert
08-29-2013 04:04 AM
Grussdi Norbo,
I could observe the same behaviour than ouadji. This thread follows one on the french communitiy.
From some benchmark I did, it seems like the structire is folded but it is not displayed as foldable.
Does anyone knows why it is not displayed as foldable even though it seems to be folded once the code executes?
08-29-2013 04:14 AM
Florian,
are you referring to the code from the OP (for loop with N=5 and buidling an array of i+12)?
If so, disabling debugging and then forcing a re-compile (easiest way: execute the VI) will display the loop as folded as expected.
If you miss to recompile the VI, display of constant folding will not be updated.
Saving the VI does not guarantee a recompile as for instance the source code could be separated from the VI-file ("Separate Compiled Code From Source File" option).
Norbert
08-29-2013 04:16 AM
thank you Norbert_B for this perfectly clear explanation about how does the compiler works
@Todd_Lesher : "Oh, 2013, too"
( "Oh" ) ... yes,you're right ... besides, I knew it. It was completely out of my mind.
08-29-2013 04:33 AM
Another sidenote:
Constant folding is present in LV since... i think somewhere 3 or 4....
But due to compiler changes, also the way of display changed.
For instance LV 7.x and earlier compiled the code as soon as changes have been done to the block diagram (except adding comments and similar). As those versions also didn't supply the separate compiled code option, the whole VI changed and display of constant folding could have been done immediatly.
With changes of the compiler in newer versions, compilation is done only in specific situations so update of display is NOT done immediatly anymore.
hope this helps,
Norbert
08-29-2013 04:48 AM
Yes, I am referring to the code from the first post. Here (class computer with LabVIEW 2012) only the wires outside the loop is shown as folded. The loop itself isnt.
As I mentioned in the previous post, in the original french post we were working on some more complex VI where, according to benchmark, it seems like the loop is correctly folded. Just doent seem diplayed as foldable. I was also wondering if there was an explaination (like the optimisation process for the loop is not constant folding but another one which would explain its optimized but not shown as folded) or if it could be a cosmetic bug where some folded loop are not displayed as "foldable".
And both normal coompile and force compile did not showed the effect 😉
08-29-2013 07:39 AM
Please put an indicator after the for loop or something that uses the array as an input.
Otherwise you will not see the "constant folding lines". (at least this is what I noticed in LV2012SP1)
It could have something to do with the fact that (without an indicator or further usage of the auto-indexed array) the code is just creating a "useless" array.
08-29-2013
07:42 AM
- last edited on
05-02-2025
07:51 PM
by
Content Cleaner
Good point, Thierry. Could be a reason.
If there is no consumer for the data, LV compiler optimization will detect the code as dead code (EDIT: even though it is no real "dead" code) and will hence remove the complete code. So constant folding will not be in question as there is no code anymore left to fold.... 😉
See more information on LV compiler optimizations here.
Norbert