From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

how improve MathScript speed & how much fast in 8.2

Hi Graham,

 

I don't think I have access to the profile that you updated. In any case, I think I'm making this more difficult than it needs to be. You can email your code to me at my NI email address: it's the usual firstname dot lastname at ni.com.

 

Thanks!

 

Jesse Attas

LabVIEW MathScript R&D

0 Kudos
Message 11 of 20
(5,561 Views)

hey guys,

 

I'm using labview 8.6. Could you help me find a list of 'recommended' matrix operations (instead of the already working while/for loops), as i too experience a slow execution speed when using mathscript?

0 Kudos
Message 12 of 20
(5,434 Views)

Under Mathematics -> Linear Algebra you have lots of matrix operations, especailly the common ones of AxB, A dot B and similar. I suspect you'll find almost everything you need there. 🙂

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 20
(4,918 Views)

Make sure you break down the code into lots of seperate nodes! Also put them in seperate subvis. I've got a single vi with lots of mathscript nodes that my PC can't even open! Lots of subvis = smaller file sizes.

 

 

0 Kudos
Message 14 of 20
(4,915 Views)

hmm 

 

i find mathscript nodes still run thousand times slower than matlab.

 

I thought its because the way labview implement their data flow paradym. My hypotheiss each block (labview block) has a harded coded computational value. Probably what the labview compiler does it goes though your vi and computes this the computational value of each block. It figures out whats running in parrelel and allocates processor priority based on the amount of computation and timming you specify for each parralel line.

 

But the problem is a mathscript node is a single block, and it can't have a harded coded measure of computation because its dependent on what you write in the script. 

 

Also with a data flow paradym, blocks get executed when the recieve there inputs. So it has to have some system (polling for instance) of recieving inputs. And perhaps there is a mis-allocation in how much processor is actually allocated to executing a sigle mathscript node. So more time is spent waiting for inputs ect that executing a single block so your whole system slows down.

 

I tested an ICP function in mathscript and it was more than 1000 times slower in labview. I guess this is what happens when you try and integrate imperative type languages with this high level data flow language. In matlab it allocates everything to a single process and executes everything line by line rather than worrying about parraellism, but i guess thats the price of parralellism. 

0 Kudos
Message 15 of 20
(4,297 Views)

Your post is full of vague statements using big words but you don't even mention your LabVIEW version. We want facts!

 

What is an "ICP function", this can have many meanings! What are your speed numbers?

 

Please post your benchmarks. Throwing out numbers does not make them believable until we can reproduce your findings independently and analyze your code. Did you compare the speed with a native LabVIEW implementation of the algorithm or just with a mathscript node in LabVIEW? Are you sure all code is optimal? How did you measure execution speed?

 

You are talking about dataflow and parallelism of LabVIEW, but then you post in the mathscript forum, leading us to believe that you are actually talking about matschript. Which is it?

 

Dataflow does NOT involve polling. As a first step, you might want to start reading some introduction to the LabVIEW compiler.

 

So, are you saying that executing a process in a single thread is always faster that untilizing all available CPU cores? Come on!

 

Please stick to statements that you can back up with facts. Your entire post is based on assumptions and about as stable as a house of cards. 😄

 

 

0 Kudos
Message 16 of 20
(4,292 Views)

Hi 

 

My labview version is 2012 and by ICP i mean iterative closest point - matching. Basically using least squares or some optimisation algorythm to repeatedly untill you find the transform to align two sets of points.

 

I profiled my code in matlab it ran in 0.117 seconds. (using the matlab code profiler) 

I ran the same test in labview (using mathscript - some modifications ie no function calls copied in user defined functions) 

And the code ran in 2.18 seconds (using the labview code profiler ).

 

Which is close to being 20 times slower than matlab...

 

earlier my code was running slow because of the way i made my timed loop. I enabled reetrant execution (which was recommended) I think this was the reason it was running so slow, because the function was getting called too often as the timed loop tried to maintain a certain frequency.

 

Now i have the mathscript node inside a timed sequency so i could set the priority to max. (Which i think helps ) 

 

I guess matlab is more optimised for this kind of code.

 

One of my friends said if you convert the code to native labview code it will be much faster especially if you remove the loops. Also i guess i could use some global variables. Does anyone know how to create a mathscript global variables that can be acessed by all mathscript nodes AND through subvi's?

 

 

0 Kudos
Message 17 of 20
(4,268 Views)

OK, now it's 20x instead of thousands of times slower. Interesting...

 

Reliable benchmarking is very difficult and from your desciptions of using timed loops and timed sequences and setting silly priorities, it does not sound like you know what you are doing at all. Who is recommending things to you (e.g. reentrant execution) and what are their LabVIEW qualifications?


@Sentinal_Bais wrote:

Now i have the mathscript node inside a timed sequency so i could set the priority to max. (Which i think helps )  


There is no need to involve thinking. Try with and without and compare the results.


@Sentinal_Bais wrote:

I guess matlab is more optimised for this kind of code.


You are still guessing wildly. Why don't you attach your benchmarking code so we can judge for ourselves? Thanks!


@Sentinal_Bais wrote:

One of my friends said if you convert the code to native labview code it will be much faster especially if you remove the loops.


You are talking about an iterative procedure here. This is very difficult (e.g. impossible) to do without loops. Loops are extremely efficient. Please explain your reasoning.


@Sentinal_Bais wrote:

Also i guess i could use some global variables. Does anyone know how to create a mathscript global variables that can be acessed by all mathscript nodes AND through subvi's?


Why are you always guessing? 😄 That sentence makes absolutely no sense.

0 Kudos
Message 18 of 20
(4,263 Views)

Here's the document which said you must place mathscript nodes in timed structures and pre-allocated clones 

http://zone.ni.com/reference/en-XX/help/373123C-01/lvtextmathmain/rt_determ_guide/

 

It also gave some other tips 

 

also for code profiling i use the labview tool ( tools >> profile >> performance and memory 

for matlab i used type >> profile viewer (command area) and in the gui where it says "run this code" type test3

 

The function you are interested in is the runtime of ICPv7.m and icp.vi

 

I have attached both the matlab code and the vi's i used 

 

also when i meant remove loops, i meant removing the loops inside the mathscript node and have the mathscript node inside a labview loop. 

 

-- edit also i accidently had shared clone allocation as - pre-allocate in the version of icp i attached

0 Kudos
Message 19 of 20
(4,255 Views)

Thanks for the additional information. I'll look at it next week.


@Sentinal_Bais wrote:

Here's the document which said you must place mathscript nodes in timed structures and pre-allocated clones 

http://zone.ni.com/reference/en-XX/help/373123C-01/lvtextmathmain/rt_determ_guide/

 


This document is specific to mathscript RT applications deployed to realtime targets. Does this apply to your scenario or are you running on a PC?

 

 

 

 

0 Kudos
Message 20 of 20
(4,247 Views)