LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop taking way too long to execute

Solved!
Go to solution

Hello fellow LabVIEW users

 

I have encountered huge problem that following for loop takes way too long to execute, I need to run two same for loops like the following one and they both together take horribly long time - 18 seconds on average. Surprisingly, when I combined both loops it took even longer.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

For loop above is doing (or should do) following part of code:

 

for i = 1 : 11850
    signalAvr(i) = signal(i);
    for j = 1 : 149                 
        signalAvr(i) = signalAvr(i) + signal(i + j);
    end
end    

 

Is there any way of speeding up this loop? What am I doing wrong?

 

Thanks

Smdx

0 Kudos
Message 1 of 8
(5,079 Views)

The build array is taking a lot of time because it is constantly grabbing more memory.  Instead, use the autoindex tunnel to build your array.  LabVIEW will preallocate the memory for the array and will run a lot faster.


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
0 Kudos
Message 2 of 8
(5,053 Views)

One thing that is absolutely killing you is the fact that you're reading a local variable 1765650 times each time you run this vi.

0 Kudos
Message 3 of 8
(5,050 Views)

I think you are doing it way to complicated. 

 

Try this:

ArraySum.png

 

NOTE: My local variable is somehow **bleep**ed. The reference control together with the property node should be a local variable.

0 Kudos
Message 4 of 8
(5,049 Views)
Solution
Accepted by Smdx

I haven't fully tested it, but see if this will work for you.  It is a lot simpler.

 

EDIT:  Ok, dkfire beat me to it.  At least we came up with the same solution independently.  I just use the autoindex tunnel where he preallocated the array and replaced elements.  Both ways will get you the same result.


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
0 Kudos
Message 5 of 8
(5,044 Views)

@dkfire wrote:

 

 

NOTE: My local variable is somehow **bleep**ed. The reference control together with the property node should be a local variable.



Use the Code Capture Tool, it is so much better than the built-in LabVIEW snippet menu choice.  It doesn't break locals and references.

Message 6 of 8
(5,027 Views)

Looks like you guys beat me to it, but I will post my solution anyways.SigAvr.PNG

***EDIT: I need a shift register in the inner loop and should be autoindexing on the outer loop****

SigAvr EDITED.PNG

0 Kudos
Message 7 of 8
(5,026 Views)

@lacVIEW wrote:

Looks like you guys beat me to it, but I will post my solution anyways.SigAvr.PNG


That solution will not work.  For that method, you need a shift register in the inner loop and you should be autoindexing on the outer loop.


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
0 Kudos
Message 8 of 8
(5,021 Views)