LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Preallocated SubVi in a loop

Solved!
Go to solution

I've inherited some code for Labview 2012, and it's running slower than the users would like. I've determined that by changing a certain subvi to preallocated clone, it speeds up the execution greatly. However, I want to make sure that I'm not getting myself into trouble with it.

 

I've attached a simplified snippet. Basically, the Values array is composed to temperatures, pressures, flow rates, calculated values, etc. The subvi consists of a case statement with a number of different calculations which modify the output. The map array determines which indexes of Values are being used for the inputs & outputs.

 

My question is:
If the first iteration of the main loop modifies an index of the Values array which is then used as in input for the second iteration, will Labiew use the newest value, or based on the cloning will it use the older one?

 

I will not be running anything in parallelized loops.

 

Thanks,

Jacob

0 Kudos
Message 1 of 6
(4,115 Views)
Solution
Accepted by topic author jacobdiemer

You are storing the array in the shift register and passing a version of that into the subVI.  So it will use the latest value of the array.

 

All the Preallocated Clone does is create a copy of the VI everywhere it is used.  Each have their own memory space and can operate in parallel.

 

The non-reentrant only allows for a single copy of the VI, meaning it can only have one caller at a time.  If being called at multiple places, then whoever got there last must wait for the VI to finish running before it can use it.

 

The other reentrant option is Shared Clone, which creates a "clone pool".  This is similar to the preallocated clone except that the clones are only created when needed.  This causes a little more latency, but is more memory efficient.


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 6
(4,096 Views)

On every iteration it will be the same instance of sub-vi. 

0 Kudos
Message 3 of 6
(4,094 Views)

Thanks, crossrulz.

0 Kudos
Message 4 of 6
(4,069 Views)

Your main question already got answered, but as a side note if you're looking to speed up those loops even more, you can try either changing the SubVI to have inlining enabled, or change its priority to "Subroutine", or both.  

 

Both of those options have restrictions based on the contents of the SubVI though, so one or both of them might not even be an option.

0 Kudos
Message 5 of 6
(4,059 Views)

@jacobdiemer wrote:

I've inherited some code for Labview 2012, and it's running slower than the users would like. I've determined that by changing a certain subvi to preallocated clone, it speeds up the execution greatly.


  • Renetrancy setting should have no impact. Maybe you changed something else? (Maybe you disabled debugging or maybe also inlined the subVI (which requires preallocated clones)).
  • How do you measure "performance impact"? This is quite simple code and should execute very quickly unless the input arrays are gigantic or the subVI solves a very complicated math problem. What are typical input sizes and values?
  • There will also be a performance difference if the panel of the subVI is open versus closed.
  • Can you attach the actual code instead of a picture? (we cannot see settings from a picture!)
  • I assume that you changed the subVI that shows on the diagram picture near the center. Is this correct?
  • How big are these arrays? What are typical values?
  • One poor design is the fact that some of the array control terminals are inside the loop. All these control terminals belong before the loop. (If they would change at random times during the execution of the loop, your results would be completely unpredictable and if they don't change during the execution of the loop, they can be treated as loop invariant code and optimized by the compiler. If the terminals are inside the loop, the code needs to re-read the same data with every iteration). Simply disable indexing on the inputs to the big loop.
  • If the value wired to N of the first inner loop is never larger thant the row size of "maps", index array can be replaced by autoindexing.

For more general advice, feel free to go over our recent NI-Weeek talk about benchmarking an optimization.

0 Kudos
Message 6 of 6
(4,056 Views)