From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find array in 2D array

When on Line 0 appears 0 (we detecting indexes) then on line 3 we must subset array starting with every index (length of indexed array = 32). In VI if we increase # repeats, time of execution VI is increasing too. For example, if # repeats=5, time of execution is too low. But if # repeats=40, time of execution is very very high. How this VI can be optimized (decreasing time of execution VI, especially when # repeats>20)?

Download All
0 Kudos
Message 1 of 11
(3,801 Views)

The Append Digital Samples function is doing a Build Array operation. Since the array is of considerable size, building it within the For loop makes repeated calls to the memory manager and takes extra time. Since you are repeating data, the end size of the array is known. If you preallocate a blank array of that size and then replace rows it can all happen within the same space in memory and run faster. I tried it using the indexing output on the For loop, but it ended up being slower.

 

The While loop can be optimized as well, but it looks like you intend to do more than just count zero indexes.

 

Here's what I did.

 

Test Capture.PNG

0 Kudos
Message 2 of 11
(3,741 Views)

Please resave in 2011 version.

0 Kudos
Message 3 of 11
(3,715 Views)

OK... saved for 2011. The picture also shows what I did. Again, I only attempted to speed up the For loop.

 

0 Kudos
Message 4 of 11
(3,691 Views)

Is it possible while loop to optimize?

0 Kudos
Message 5 of 11
(3,675 Views)

It is possible, but there appears to be unused code in the While loop. It is not clear if the lower shift register needs to do anything. Without understanding the whole requirement, it is difficult to suggest optimizations. A typical technique is to avoid While loops if there is any way to know the maximum number of iterations in advance. For loops are much faster because there doesn't need to be a decision made each iteration, and memory management is easier for the compiler.

0 Kudos
Message 6 of 11
(3,642 Views)

@Photon_Dan wrote:

Without understanding the whole requirement, it is difficult to suggest optimizations. 


In this VI when on Line 0 appears 0 then on line 3 we must subset array (length of indexed array = 32).

0 Kudos
Message 7 of 11
(3,623 Views)

I managed to get the execution speed on my PC with 40 repeats down from about 1.5 seconds on the original VI to about 105 msec.

 

Now, how about some Kudos?  Smiley Happy

0 Kudos
Message 8 of 11
(3,609 Views)

@Photon_Dan wrote:

I managed to get the execution speed on my PC with 40 repeats down from about 1.5 seconds on the original VI to about 105 msec.

 

Now, how about some Kudos?  Smiley Happy


It's OK but you define Indexes (when 0) wrongAs we can see from Graph on Line 0 indexes when 0 are 0, 51, 102 and so on.

0 Kudos
Message 9 of 11
(3,594 Views)

Oops... sorry I missed that. When you expand the signals out into a 2D array of boolean like I did instead of using the slow built-in function, you get a reversing of the bit order so line 0 is at index 3. I also messed up the storage of the indices. This looks much better.

Message 10 of 11
(3,583 Views)