LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow array indexing when using a subroutine

Solved!
Go to solution

I have written some labview code that extracts a certain range of data from an analogue waveform. (3 options - Last Value only, All Values or a Specific Range)

I am acquiring what I consider large ammounts of Data (Analogue Samples at 1 MHz for 20+ seconds).

I am proceessing the data in a consumer loop and found that the indexing functions slowed to a crawl (~100mSec per seek).

The slowing is a linear relationship to array size.

 

My debug analysis found that if I change one of my subroutines to inline code, the speed problem went away.

 

Why is is this???

 

My best guess is that Labview is taking a copy of the array to send to the sub VI.

I am not modifying the data in the subroutine, is there any way to tell LABVIEW not to do this?

 

Attached are 2 versions of my VI, speedy has the subvi in-line (sorry about the mess) the other (sluggish) uses the code in subvi form.

The test VI's create an array of increasing size and then measures the seek time for the array indexing and graph's it.

 

 I am using Labview 8.5.1

 

 iTm

 Long time user first time poster.....

 

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
0 Kudos
Message 1 of 6
(2,912 Views)

Tim,

 

I was not able to run the test VIs right out of the zip file as they were missing your custom controls.   I went ahead and disconnected the constants and controls/indicators from the typedef and was able to run the VIs as they were.  I have attached two images (one of each test) showing little difference between the two.  One thing I noticed with the subVI code vs the inline is that there was a constant input not wired up (so it would use the default value).  I'm assuming the default value was '0' on the typedef anyway so this shouldn't matter, but that was the only difference I see.

 

Are you doing other things when this function is running?  It never got to 100ms/seek for me.

Regards,

Jared Boothe
Staff Hardware Engineer
National Instruments
Download All
0 Kudos
Message 2 of 6
(2,862 Views)

My Bad...

 

In my efforts to work around the problem I found a fix and inadvertentlly included it in the zip.

 

Here is the problem back again.

 

I think I may be onto it...

If I close the subVI the performance is good.

Open it, not so good.

Smells like panel refresh.

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
0 Kudos
Message 3 of 6
(2,836 Views)
Solution
Accepted by Timmar

Tim,

 

You are exactly correct.   What you might look into is reentrant execution of your VI.  It just depends on what you are wanting to do with the end-result.  Reentrant will solve this problem, but wont update the data on the front panel.  

 

Check out the following KB: Differences Between Reentrant VIs (Preallocate), Reentrant VIs (Share Clones), VI Templates, and Dyn...

Regards,

Jared Boothe
Staff Hardware Engineer
National Instruments
0 Kudos
Message 4 of 6
(2,811 Views)

Timmar wrote:

If I close the subVI the performance is good.


You migh want to set it to subroutine priority, this will prevent any FP updates, even if the panel is open.

0 Kudos
Message 5 of 6
(2,806 Views)

To quote Bixby Snyder (Robocop) "I'd Buy that for a Dollar!".

 

Thanks Jared for the Starting point and the refinement by altenbach, Problem Solved.

 

As a heads-up to others trying this solution, it makes subroutine Debug a little harder (even cryptic at times) the data you might be looking for will be missing.

 

I would recommend writing some notes on the front panel and diagram saying:

"This is in subroutine execution mode. For correct debug change me to normal priority there will be performance degredation when the vi is open,"

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
0 Kudos
Message 6 of 6
(2,766 Views)