LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

speed up execution of data analysis VI

Solved!
Go to solution

Hi,

 

I have written a labview vi to help me analyze some rather large data sets. The vi works however its very laggy and uses a lot of memory. Was hoping an expert could take a look at my code and give me some ideas on how I can modifying it to improve the speed of  which it runs. I have attached my labview vi. Hopefully someone can help.

 

Kind regards, R  

Message 1 of 6
(4,647 Views)
  • You're reading a writing from a ton of property nodes each iteration and running all the calculations every iteration. You onl tneed to read the property node values when a cursor is moved, right? Why not set up an event structure that triggers values to be re-calculated when the user interacts with the cursors.
  • You're writing the plot name, scale labels, etc every iteration which is overkill. Learn how to make an initialization state to set these variables and then you don't need to repeat that code portion.
  • You're loading the data from file with every iteration as well. That's slow and completely unnecessary.
  • You have a bunch of duplicated data buffers because of your local variables and even duplicated property nodes. Why don't you just use data wires like LabVIEW is meant to use? You use too many local variables in general. Learn how to use shift registers to store data from iteration to iteration.
  • All of your code is one big race condition. Your user is going to interact with the cursors and if your code is mid-loop while they do this, some data will update at the wrong time. LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.
  • FYI, property nodes operate from top to bottom. So when you set Active Cursor property 2nd in line after reading the cursor position, you're not setting the active cursor in time.

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 6
(4,637 Views)
Solution
Accepted by rkl685

Things I see wrong.

 

1.  You are constantly re-reading the same files in a loop.  Do you expecting the files to change?  Files should be read before the loop, and data manipulated inside the loop.  I think this is your primary problem.

2.  Abuse of local variables.  You have numerous copies of AllRows for instance.  You should have a single wire coming out of the Read from Spreadsheet file to your terminal, and branch that to wherever you need it.  Many other controls are duplicated with local variables unnecessarily.

3.  Lot of dupliated code.  You are doing the same operations on numerous graphs.  You can probably simplified by putting that into a subVI and replicate the subVI.  You can probably wrap all of that up in a For Loop.

4.  Your cursor property nodes seem backwards.  You are readling the current X position before you set the Active Cursor.  That and a race condition with the other property node in parallel means you don't know which X value you read corresponds to which cursor.  Read both cursors in one node and in the proper order like this:

 

 

 

5.  Other things as well that might become more obvious once the big items above are taken care of.

 

I would recommend looking at the online LabVIEW tutorials
https://learn.ni.com/learn/article/labview-tutorial

0 Kudos
Message 3 of 6
(4,631 Views)
Solution
Accepted by rkl685

Basically all of your local variables are unnecessary. I deleted your "all rows" variables and got rid of all your duplicated property nodes for the cursors and it looks like this. There's plenty left to fix, but this is a good functional improvement. You need to go through and set up some subVIs. You have a lot of duplicated code still.

Alpha Instrument Data Viewer.png

This is a Snippet! Drag it to your LabVIEW block diagram to import the code directly.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 6
(4,619 Views)

Thanks so much for the advice and for bearing with my weak labview skills. I was able to make most of the changes recomended and the VI is working much better. I will review the tutorial you recommended as soon as I get some time. 

0 Kudos
Message 5 of 6
(4,554 Views)

@rkl685 wrote:

Thanks so much for the advice and for bearing with my weak labview skills. I was able to make most of the changes recomended and the VI is working much better. I will review the tutorial you recommended as soon as I get some time. 


FYI - no time like the present.  The sooner you can start producing quality code, the better.  🙂

 

Sorry, those were supposed to be words of encouragement, but somehow it seems a lot harsher than I had intended.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(4,535 Views)