LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

optimization nested loops for speed

Solved!
Go to solution

Hi Bob, could you save that as a 2014 or lower VI? Now I'm curious!

0 Kudos
Message 11 of 20
(2,930 Views)

Gregory,

 

     Sorry, I was running errands.  I'm going to post this as a 2014 Snippet -- it's short and simple enough, and illustrates the points.  Note that I use the High Resolution Timer (the stop watch) which is one of the NI "Hidden Gems" that is available through the LabVIEW Tools Network.

 

Array vs Matrix.png

Bob Schor

 

Message 12 of 20
(2,902 Views)

Same but with the high Perfromance library, which is now free.

 

Cheers,

mcduff

 

Schor.png

Message 13 of 20
(2,888 Views)

"the high Perfromance library, which is now free."  Except that it is for Windows only.

 

Lynn

0 Kudos
Message 14 of 20
(2,875 Views)

Sorry. I too use a mac for everything, except for LabVIEW.

 

Cheers,

mcduff

0 Kudos
Message 15 of 20
(2,869 Views)

Thank you Bob, the matrix method is indeed quite fast, taking only about 15ms on my machine. I'm a little confused now because johnsold's array method took 135ms while yours took about 950ms, and they seem identical. Even moving the "transpose 2D array" outside of the sequence structure on yours does not cut the execution time down. I've disabled debugging on both on them, I just can't think of what else might be different...

0 Kudos
Message 16 of 20
(2,858 Views)

Note that the matrix and explicit versions are only equivalent if the input only contains positive values. If you would subtract 0.5 from your random numbers, the results are only equivalent if you add an absolute value function after the matrix operations. (Seems to be pretty cheap).

0 Kudos
Message 17 of 20
(2,839 Views)

OK, guys. I get about 30% the matrix speed using the following hybrid approach, but when I enable parallelization on my dual Xeon with 16 hyperthreaded cores (i.e. 32 virtual cores), it is about 5x faster (~6-7ms for Bobs benchmark), i.e. a 15x speedup overall due to parallelization for that code fragment. (I have not tried the hi perf libraries yet.)

 

 

Message 18 of 20
(2,827 Views)

Altenbach catches my carelessness, again!  When I originally tested the Matrix method, I had the Absolute Value function in there, but when I went to make the code "pretty" so I could post it here, I forgot it!  Dang.  My guess is it will have a minimal effect on the timing (but, still, My Bad ...).

 

Bob Schor

0 Kudos
Message 19 of 20
(2,809 Views)

I would like to thank everyone for your prompt feedback. It has been extremely useful.

The fastest way to do it (at least on my PC) was to do a simple matrix multiplication (thanks Bob_Schor) together with the use of the High Performance toolkit (thanks mcduff).

 

Adrian

0 Kudos
Message 20 of 20
(2,679 Views)