LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fastest loop computation speeds

Hello,

 

I've been working on a program that scans images pixel by pixel and I was doing this with a double for-loop because this is  how I would normally go about this. I created a double for-loop in both a LabView VI and in a MATLAB script call. I thought that since the LabView VI can do parallel processes it would run faster than the MATLAB script which is serial. I found our that the MATLAB script call actually runs about 1800 time faster which got me wondering...

 

What is the fastest external code that Labview can work with?

 

 

0 Kudos
Message 1 of 18
(3,732 Views)

Sounds strange, LV shouldn't be much slower, if at all. Can you post the code? Did you setup the loops for parallell processing? (they're serial per default)

 

/Y 

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

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

Here's a screenshot of my code. I tried to make it as parallel as possible but the problem itself is quite serial in nature. I welcome any suggestions

0 Kudos
Message 3 of 18
(3,690 Views)

It's often more helpful to attach your VI, not just an image of it.

 

Does the code you posted produce the expected results?  It looks to me like you should be using shift registers in the for loop instead of tunnels for the arrays.  This will probably speed up the loops, and give you better results.  From what I can see in that image, if the false case is normally executed, you're replacing an array element on each loop cycle and then discarding the modified array on the next loop iteration, which is both inefficient and probably algorithmically incorrect.

0 Kudos
Message 4 of 18
(3,678 Views)

Also, I have you compared the timing of the execution of just the loops? Your performance hit may be one of the other parts of your code in the subVIs.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 18
(3,671 Views)

As someone already mentioned this code cannot produce the correct results as it lacks shift registers. However, it is even quicker to use auto-indexing. The way your code works there is no reason not to use auto-indexing. Post the VI and we can optimize it for you.

0 Kudos
Message 6 of 18
(3,664 Views)

Well, your question was not how to improve the current LabVIEW code (and yes, there is probably quite a bit of slack left! ;)), but why it is orders of magnitude faster than Matlab.

 

You have not shown us the matlab script version, so we can only guess.

 

  • What are the actual execution times of thee two versions and how do you measure it?
  • Is the LabVIEW execution time as expected for the array sizes?
  • Do both versions give the same result?
  • What is the CPU and memory use for the two versions?
  • You could probably adapt your code using the parallel FOR loop, giving you another x speedup on multicore hardware. In your current code design, it cannot really do much in parallel. How is the CPU usage when running?
0 Kudos
Message 7 of 18
(3,652 Views)

Ok so I isolated just the double for-loop and MATLAB peices of the my code (below) and made them logically equivalent (using the same processes at the same times in each algorithm). The performance difference dropped drastically, which may be because of my high proficiency in MATLAB and my low proficiency in Labview, to about a difference of 4 times (0.465 sec in MATLAB 1.785 sec in Labview). The MATLAB code generates the result I'm looking for but the LabView code does not which maybe because of me not using shift registers (I'm new to this so I need to look this up and learn to implement it which I will be doing in the mean time).

 

As per altenbach's request computation data is...

 

MATLAB                                LabView

10-28% CPU usage                12-16% CPU Usage

2.08 GB memory usage          1.785 GB memory usage

0.465 sec to complete            1.785 sec to complete

 

I left the method I used to get the times in the examples.

 

Thank you for any insight you can provide to making this difference shift in favor of LabView

Download All
0 Kudos
Message 8 of 18
(3,623 Views)

Without looking at your MATLAB code at all... try this simple change to your LabVIEW code: change the tunnels (the blue boxes on the border of the for loops where the arrays enter and exit the for loops) to shift registers.  Right-click on each incoming tunnel, choose "Replace with Shift Register" and then click the corresponding tunnel on the outgoing side of the for loop (matching inputs to outputs).

 

You might also want to use the "In Range and Coerce" function instead of separate Greater/Less Than comparisons, and you could change the numeric representation of the 0 constant in the case structure to a U8 to match the type of data in the array (right-click, Representation).

Message 9 of 18
(3,618 Views)

Your algorithm in LV is not the same as in MATLAB.  You need a square root in the calculation of hyp.

 

Can you post some typical data arrays for those of us who do not have IMAQ? Also the expected result so we can check things.

 

You definitely need shift regsiters. I think you can use autoindexing although a transposition may be needed.  Altenbach will shortly remind us that suing complex math may simplify things, also.

 

Lynn

Message 10 of 18
(3,597 Views)