LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building array of clusters of 1D array slows down after each call

Solved!
Go to solution

Hi all,

 

I had a problem for which I found a workaround, but I would like to understand why this is happening.

Consider the code snippet below.

 

Capture.PNG

I am binning a 2D array into a 1D array by transforming the 2D coordinates in order to get the average value and standard deviation of each bin. Because the number of elements is not the same for each bin I used a Build Array and stored this in an array of clusters.

 

This might not be elegant from a memory management pov but it performs well enough on the first run, a few hundred milliseconds. However each call takes significantly longer than the previous. The 2D array size is typically around 600 x 300 elements and the binned array size around a few thousand elements. After a few calls it can take over 10 seconds to execute, both in developer mode as in runtime environment. There does not appear to be a memory leak.

 

By using Request Deallocation the execution time stays more or less constant. It seems the initialization of the 1D array of clusters does not result in the same state as during the first call.

 

Is this a case of the LabVIEW compiler failing to outsmart the user? Am I making things worse by using the In Place Element Structure?

0 Kudos
Message 1 of 15
(5,912 Views)

Hi Ramon,

 

can you provide the code from that image as a VI/snippet, together with some typical input data?

 

Which LabVIEW version do you use?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 15
(5,907 Views)

Hi Gerd,

 

It seems I underestimated the sizes.

See attached VI with typical values.

0 Kudos
Message 3 of 15
(5,882 Views)

Since you're adding at the beginning of the Array it'll need to reallocate and copy the Array each time.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 15
(5,878 Views)

@Yamaeda wrote:

Since you're adding at the beginning of the Array it'll need to reallocate and copy the Array each time.


I tried adding at the end but that also does not seem to help for next calls.

 

Without deallocation:

RamonG_0-1597665954227.png

 

With deallocation:

RamonG_1-1597666003646.png

 

Download All
0 Kudos
Message 5 of 15
(5,873 Views)
Solution
Accepted by topic author RamonG

Hi Ramon,

 

right-click the IPE and select "Remove IPE…", then save the VI.

 

This cuts down the loop times from ~800ms…3800ms (start to 5th iteration) down to ~400ms (for all iterations)! (LV2020, 32bit on Win8.1-64bit)

 

(Prepending or appending the new element to the inner array doesn't make a notable difference.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 15
(5,872 Views)

@GerdW wrote:

Hi Ramon,

 

right-click the IPE and select "Remove IPE…", then save the VI.

 

This cuts down the loop times from ~800ms…3800ms (start to 5th iteration) down to ~400ms (for all iterations)! (LV2020, 32bit on Win8.1-64bit)

 

(Prepending or appending the new element to the inner array doesn't make a notable difference.)


That did the trick.

I guess it was a case of me failing to outsmart the LabVIEW compiler 😛

Message 7 of 15
(5,860 Views)

Hi Ramon,

 

when the IPE was new it helped the compiler to get smarter.

Nowadays the IPE most often is not needed anymore because the compiler is smart enough to recognize the typical use patterns…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 15
(5,848 Views)

Hi GerdW,

 

How can I remove the IPE in LV2017?

0 Kudos
Message 9 of 15
(5,522 Views)

Hi Harvey,

 

read message #6

 

Why don't you attach your VI?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 15
(5,520 Views)