LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathscript speed of execution

Hi,

 

   I wrote a vi using Mathscript to do a series of manipulations (append, reshape, etc.) on four matricees of up to 1024 x 1024 size, and compared it to a similar routine written exclusively in LabVIEW (see attached comparative VIs).  The Mathscript version executed ~10x more slowly, and took considerably more memory.  Is this to be expected, or is there something I can do to speed the Mathscript version?

 

Thanks,

Eric

Download All
0 Kudos
Message 1 of 5
(7,337 Views)

Yes, this is probably as expected. A factor of 10 is actually not that much. 😉 Mathscript carries more overhead due to the more general functionality.

 

If performance is critical, you should probably use wires.

 

Also your wire version does not seems very optimized, for example:

 

  • Why do you read from local variables if you can use wires? (e.g. X pixels, y pixels, bidirections scan, tau, etc.) Don't be afraid to branch a wire! A local variable always forces another datacopy. All terminals are right there, none of your locals are needed at all.
  • All your final arrays are I16, so why are you carrying 4x more data (DBL!) through the algorithm? In fact, there should not be anything orange on the diagram at all.
  • You also have potential race conditions. There is no guarantee that e.g. the tau terminal gets current data before it's local is read in the upper right.
  • It is sufficient to use a single "index array", you can resize it for two outputs.
  • It would be simpler to use a single case structure containing two FOR loops, your two big cases are 100% syncronous.
  • A simpler way to determine even/odd would be a bitwise AND with 1, followed by a case structure with two numeric cases 0=even, 1=odd).
  • All input terminals should go before the sequnce. 
  • The output terminals should go after sequence, you don't want to potentially measure the FP updates.
  • for a meaningful benchmark of the algorithm, disable debugging.
  • Use the correct representations (x pixel, y- pixel, etc.) Since they are used as array indices, make them I32. Eliminate all 22 coercion dots!
  • ...

 

0 Kudos
Message 2 of 5
(7,331 Views)

BTW, could you check if the mathscript version that you have attached is OK. If I try to open in in LabVIEW 8.6, LabVIEW stops responding.

 

I cannot open it. Wondering what's wrong....

0 Kudos
Message 3 of 5
(7,321 Views)
Thanks a lot for your suggestions on improving my codes. I just checked the mathscript version and it worked on my computer (LabVIEW 8.6). Do you know where I can find benchmark measurements of mathscript in LabVIEW?
0 Kudos
Message 4 of 5
(7,306 Views)
Hello altenbach,

I also see a hang if I try to open the VI in LabVIEW 8.6.  However it varies from machine to machine as there are some where it does not hang.  We are looking into the problem.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
Message 5 of 5
(7,259 Views)