LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

a lot of time to multiply two arrays

Hi Larson,

I'm not an expert on the use of "formula node code" - but I'd be very surprised if it were significantly faster.

I'd like to think that LabVIEW was producing fairly well optimised compiled code - and since the formula node code is only a "psuedo C code" subset then there may well be some LabVIEW compiling loss/overhead even then.

I can confirm that LabVIEW 7.1 and 8.0 are dramatically faster than version 7.0 when running your example code - on my 1.8GHz machine, LV version 7.0 took 42 seconds, but version 7.1 and 8.0 did it in 0.45 seconds (version 8.0 took 0.34 secs on repeated calls).

Mark.

0 Kudos
Message 11 of 24
(2,944 Views)
(Forget the formula node!!)
 
I have been surprised by the huge differences quoted between LabVIEW 7.0 and 7.1, because I only see a factor of 10 improvement.
 
Here are the quoted speedups:
 
altenbach (Pentium M) 10x (3.7 vs. 0.36)
Nomis (Pentium 4) 63x (19 vs. 0.3)
Mark H (??) 93x (42 vs. 0.45)
 
For comparison, I have modeled the AxB fuction using basic operations and FOR loops and it is only about 15x slower than the matrix operation under LabVIEW 7.1 and only 1.5x slower under LabVIEW 7.0.
 
 
Mark, what is your CPU type?
 
It would seem that for Nomis and Mark, explicit multiplication should be faster under LabVIEW 7.0. Could you post your results taken with the attached VI?
 
Notes:
  • The two methods don't give exactly the same result due to rounding erros, but the sum of the squared differences between the two is less than 10^-16 under LabVIEW 7.0 (Surpisingly, the differences is even a few order or magnitudes less under LabVIEW 7.1).
  • Also note that the loop version is functionally not identical, because it does not check for error conditions in the inputs (e.g. if the number of colums in A is not equal to the number of rows in B).

Message Edited by altenbach on 11-24-2005 08:40 AM

Download All
0 Kudos
Message 12 of 24
(2,939 Views)
Hey Altenbach,
   I double checked my CPU & it's actually an AMD XP2400+ (which I believe has a clock speed of 1.8 Ghz)

Results:

LV7.0     matrix 20165ms, loop 20775ms, chisquare 2.08822E-17
LV7.1.1  matrix 338ms, loop 18005ms, chisquare 1.82393E-21


cheers,
  Simon


0 Kudos
Message 13 of 24
(2,911 Views)
Just for fun, I pulled it into LabVIEW 8 to see if the new Matrix data type would make a difference.



Doesn't really seem to. I avereaged times of 300ms for the matrix and around 4 seconds for the array/loops.

This on a P4 M 2.0 GHz WinXP Pro.

Ed

Message Edited by Ed Dickens on 11-24-2005 11:42 AM



Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 14 of 24
(2,909 Views)


@Ed Dickens wrote:
Just for fun, I pulled it into LabVIEW 8 to see if the new Matrix data type would make a difference.
Ed,
 
The matrix data type does not change the algorithm, so it should be similar. One important difference between array and matrix data types is the way basic operations are carried out.
 
In this case, you could use a basic multiply operation on the two matrices and it will perform a true AxB matrix operation instead of a plain element-by-element multiply as in the case of arrays. 🙂
 
 
Isn't this cool!
 
The modification in the above picture gives exactly the same result as by using the AxB matrix subVI. (If you would swap the two inputs to the multiply, the result is an empty array, also as expected).
 
 

Message Edited by altenbach on 11-24-2005 11:11 AM

0 Kudos
Message 15 of 24
(2,901 Views)
Let's not forget that LabVIEW 8.0 has yet another way to do this: MathScript!
 
Seems to be slower than the matrix operation, but faster than the loops. 🙂 Pretty impressive considering all the extra baggage of Mathscript 😮
 
 
(Deep under the hood Mathscript seems to use the same algorithm, because chisquare is zero ;))

Message Edited by altenbach on 11-24-2005 11:34 AM

Download All
0 Kudos
Message 16 of 24
(2,895 Views)
Hello Altenbach!
 
First of all, thank you for all your replies.....is very interesting all the replies from you and from the other people about this threat.
 
I want to ask you because you say (forget the formula node), i don't like formula node, but i want to have a reason from a "labview expert".
 
Thank you
Larson
0 Kudos
Message 17 of 24
(2,878 Views)

altenbach,

My CPU is a P4 1.8GHz with 256MB RAM.

I ran your code and these are the rough timings...

LV 7.0

MAT = 41 seconds

Loops = 43 seconds

LV 7.1

MAT =  0.5 and/or 0.75 seconds

Loops = 41 seconds

LV 8.0
 
MAT =  0.94 to 0.78 seconds
 
Loops = 48 seconds
 
There's a bit of unrepeatability in the fast "MATrix" results - probably due to the shorter measurement period, background tasks and memory availabilty.
 
At a glance it might look like LV 8.0 was slower, although I suspect this may be caused by my relatively limited amount of RAM and LV 8.0's extra memory guzzling.
 
Mark.
 
P.S. Is it just me or does LV 8 take an annoyingly long time to start up - anything between 20~40 seconds, compared to the 7 versions which only take 5~10 seconds - it's really is a bit irritating.
 
 
0 Kudos
Message 18 of 24
(2,874 Views)


P.S. Is it just me or does LV 8 take an annoyingly long time to start up - anything between 20~40 seconds, compared to the 7 versions which only take 5~10 seconds - it's really is a bit irritating. 

Yes, it seems to take fore ever to start. 60 seconds on average for me.

I currently have 512 meg RAM, but have 2 gig on order. Should be here next week. It will be interesting to see if that makes a difference.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 19 of 24
(2,864 Views)
Hallo, all,

very nice topic... Very interesting results, and I would like to say "congratulations, National Instruments!".
Such fast implementation of matrix multiplication... Unbelievable!

Usually calculations in LabVIEW are not very fast. Especially if they realized in "native" LabVIEW code.
Some mathematical operations, such as staistic, math, etc based on DLL, and fast but also not efficient enough.
When I have seen slow speed of matrix multiplication, I have tried to wrote my own DLL with simple code:

In comparison with native LabVIEW code this C code above approximately 5-7 times faster (depends from compiler. etc).
But A x B.vi (also DLL based) from version 7.1 still faster! Of course, implementation above is not very optimal, but NI done within 300 ms, and this C code needed over one second for 500x500 matrix on my computer!
Then I have checked INTEL matrix multiplication from INTEL IPP library. (function  ippmMul_mm_64f).
Also very slow! This library is optimized for Intel processors with SIMD commands and a very slow!
I has compared different LabVIEWs and below my results for three versions of LabVIEW

Intel P4 1,6 GHz, Windows2000Prof



LabVIEW 8.0 seems to be a little bit slow when executed native LabVIEW code, but speed of matrix multiplication is a very good.
Interesting, which mathematical algorithm is used by NI?

VIs and DLL with source code are attached.

Andrey.

Message 20 of 24
(2,763 Views)