LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow speed code in formula node

Solved!
Go to solution

Hi All,

What is the best method to obtain the highest speed for the code in attached formula node?

0 Kudos
Message 1 of 13
(1,374 Views)

We are graphical programmers, so we would probably not use a formula node at all. It is also confusing if you e.g. label the input to A as D1, etc. Why not name the controls as in the formula node?

 

I am not going to try to understand what you are trying to calculate, but if you point us to a website that describes the algorithm and purpose, we can probably point you in the right direction. Does the algorithm have a name?

 

What speed do you expect for large values of "u"? Complexity seems to be O(u²), so the execution time will probably go with the square of u.

 

 

0 Kudos
Message 2 of 13
(1,341 Views)

Hi Altenbach,

The code is an example you can find here:

http://electronbunker.ca/eb/CalcMethods1b.html

 

On this page you can search for:

"Function Mcoil(ByVal n1,r1,x1,n2,r2,x2,x)"

 

It is related to a mutual L between two coaxial solenoids

 

 

0 Kudos
Message 3 of 13
(1,319 Views)

I did some quick benchmarking. The formula node is 100 times slower than the native G code.

ZYOng_0-1697289502994.png

 

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 4 of 13
(1,299 Views)

Hi,

 

Try implementing it with G code completely, here I managed to reduce the time by ~60% by pre-generating the x's and y's in 2D arrays prior to the formula node. Also, some repeated calculations can be factorized to do it only once instead of in each iteration. Finally, the G code compiler can automatically detect some portions of code that are "loop invariant" and take it out of the loop for performance optimization, which I guess you don't have with formula nodes:

 

raphschru_0-1697289409188.png

 

Regards,

Raphaël.

Message 5 of 13
(1,294 Views)
Solution
Accepted by topic author Mal123

I hope my colleague @altenbach will forgive me for "poaching" on his pleasure of turning scripts from Visual Basic code into LabVIEW.  Thank you to the Original Poster for providing the reference.  Rather than tackle the function for MCoil, I did the "inner function" it calls, "mut" (which I named "Mutual Inductance", following the principle that when you are dealing with LabVIEW, there is no sense in obscuring things by choosing single letters to represent variables).

 

You can see that I added the Error Line (always a good idea), that the "loop" is now a While Loop with a "Run-until-done" condition, all the temporary variables are initialized before being brought into the While Loop as Shift Registers (because they are modified within the loop), and the final result is calculated when the loop exits.

Mutual InductanceMutual Inductance

Bob Schor

Message 6 of 13
(1,282 Views)

@Bob_Schor wrote:

I hope my colleague @altenbach will forgive me for "poaching" on his pleasure of turning scripts from Visual Basic code into LabVIEW.


Thanks. I had no intention to analyze the text code and my earlier reply was made at 2:51am here (after I got up to check something). Still, I might have a look later this weekend to see if we can squeeze another factor of two out of it. 😄

 

For example, whenever I see something like x=sqrt((A + B)**2 + z**2);, I think "complex" to get the magnitude! Of course.

0 Kudos
Message 7 of 13
(1,272 Views)

Great Bob Schor!

So it is the innner function mut and for the total function I have to merge something like the code raphschru has posted before.

I am not able to convert it in LabVIEW.

 

 

 

 

 

0 Kudos
Message 8 of 13
(1,245 Views)

Hi,

Here a revision with small modifications.

I've added square roots you forgot and dividing by a at the end. I hope now it is correct.

 

Best regards,

Mal

 

11111.png

0 Kudos
Message 9 of 13
(1,171 Views)

@Mal123 wrote:

Here a revision with small modifications.


Unfortunately, this is just a picture. Please attach your VI or at least a LabVIEW snippet.

 


@Mal123 wrote:

I hope now it is correct.


Hope is insufficient. If the algorithm is correct, it will give the correct result. Did you try for several inputs?

0 Kudos
Message 10 of 13
(1,144 Views)