LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow Execution Time of Exponential Function

Hi,

 

I am developing a program with large dataset (arrays size of around 1000*1000 elements).

I realised that my program ran quite slow when calculating exponential for each array elements.

So, I built a simple porgram to test the execution time for exponential vs multiplication on 1000*1000 array elements and found

out that the period is ~25 times longer. Attached is the program (Labview 2011).

 

The specs of my system are:

1) Windows 7

2) Intel i5 3Ghz with 4gb ram

3) Labview 2011

 

The actual program I built has a version in Matlab and uses exponential function as well. However, the execution time in Labview is around 10 times longer than the Matlab. I believe that the exponential function is the cause of this after making some analysis using built-in "Performance and Memory" tool and modification to the program.

 

Is there any way I could make the exponential function runs faster? Or any better way to handle large array operation? (I have tested array operations with nested FOR loops and paralel execution but the results is not that great.
Hope anyone can help. Thanks for any input.

 

0 Kudos
Message 1 of 20
(3,844 Views)

As comfort, e^x is twice as fast as x^y with x=e.

It's hard to compare the functions, as multiplication is a core function of the CPU making it basically instant.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 20
(3,812 Views)

A very quick test shows the a looped multiplication is faster, but it doesn't handle the decimal part ... we might work something out for that.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 20
(3,810 Views)

The strange thing is that the execution time in Matlab is much faster (i.e around 10 times faster) as compared to labview for calculating the exponential function.

I ran them on the same computer. 

 

Could you please explain further on

 

"A very quick test shows the a looped multiplication is faster, but it doesn't handle the decimal part ... we might work something out for that." 

 

I could not understand well. Thanks a lot for the input.

0 Kudos
Message 4 of 20
(3,788 Views)

Since an exponential function is a series of multiplications i simply looped the correct number of times, and it is faster, it however only handles the integer part, not the .7183.

Trying to be clever and use a variant lookup table to (in this case) only calculate once was actually 4 times slower than simlply calculating e^x.

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 20
(3,778 Views)

Benchmarking on my 8 year old laptop, an exponential function is 160ns while a multiplication is 6ns. This looks normal to me.

It would really surpise me if matlab can do it faster. Can you show us your matlab benchmarks? Is it realistic? Maybe there is some folding going on if all elements are the same. Obviously, you could do the exponential before building the array in your current code.

 

If you have a computer with multiple cores, you should wrap an autoindexing parallel FOR loop around the exponential function and you will get a speedup that is proportional to the number of CPU cores. 

Message 6 of 20
(3,639 Views)

Thank you for your answer. 

 

I am sorry, I could not upload the real code since it is large and has lots of dependency. But, I wrote simple program both in Labview and Matlab as attached.

I tried to make both program doing the same thing and put each element as random number between 0-1 to avoid any folding/optimization process.

The Labview took around 974ms to complete the task while the matlab 177ms. If the the way I implemented them are correct, the Matlab is around 5 to 6 times faster than Labview to execute Exponential function.

 

 

0 Kudos
Message 7 of 20
(3,607 Views)

It seems the exponential function isn't very parallell by default, whereas i suppose Matlabs is.

By making this very simple change i reduced the time by ~75%!

From 912ms to 284!

(Interesting side note is that my LV2014 x64 is 20ms _slower_ than the 32 bit in this case)

 

Exponential.png

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 20
(3,578 Views)

@Yamaeda wrote:

It seems the exponential function isn't very parallell by default, whereas i suppose Matlabs is.

By making this very simple change i reduced the time by ~75%!

From 912ms to 284!


Yes, I was suggesting this here. I'll try on my 16 core Xeon later. 😄 (currently using a dual core laptop only).

 

Now I need to find a computer with matlab. that might be hard... 😮

0 Kudos
Message 9 of 20
(3,575 Views)

@altenbach wrote:

Yes, I was suggesting this here. I'll try on my 16 core Xeon later. 😄 (currently using a dual core laptop only).

 

Now I need to find a computer with matlab. that might be hard... 😮


Great minds think alike. 😉

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 20
(3,553 Views)