LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory Allocation problem

I recently was given, called Make Alarm Points, which is very helpful. It takes an array, a max value, and a min value, and it outputs three arrays: one containing all the points inf the array above the max value, one containing all the points below the min value, and one containing all the points between the two values. It works very well; all I have to do is keep building my initial array for the input and build an array cluster for the output to graph it.
 
Unfortunately, I need to execute Make Alarm Points many times on an ever-growing array, and vi uses a for loop and build array functions in every single iteration, which creates a serious memory reallocation problem. I realize that I can replace the Build Arrays with Replace Arrays, but I'm concerned about having a large number of empty points in the output arrays, and the effect those points will have on the graph.
 
Does anyone have any advice for managing the size of the output arrays?
Download All
0 Kudos
Message 1 of 9
(3,403 Views)
Arrays that grow without limit are always bad, because your computer resources do have limits. 😄
 
Not only are you building an array in the main VI, you also, with each iteration (!), built multiple arrays from scratch to the final big size in the subVI. Every time the subVI executes. A memory allocation nightmare!
 
I don't fully uderstand your code. For example, why are you sending what seems to be [x,y] data to a waveform graph? Shouldn't that be an xy graph?
 
Also the way you are packaging your data "arrays of clusters containing arrays of clusters" seems a bit convoluted. Your subVI seems to reanayze the entire built-up array from scratch with each iteration, basically repeating the same analysis for the vast majority of the time. It would make more sense to only analyze the new data as it comes. In this particular case, you could eliminate the shift register in the main VI completely and only send the new data to the subVI ( and design the subVI similar to a LV2 style global). There are many other possibilities.
 
I would vote for a complete redesign of the code. 😉
 
What exactly are you trying to do? Do you have an image of how the graph is supposed to look like? What is the upper limit on the amount of data? Maybe you can stream it to disk and only keep the last few thousand points in memory?
 
0 Kudos
Message 2 of 9
(3,395 Views)
It's an XY-graph, not a waveform graph. I inherited this code, and it's a nightnare. I don't know all that much about LabVIEW; it took two weeks for me to realize that reference nodes to XY graphs are labeled "waveform graph".
 
Also, the type of data going into the graph is Array of Clusters of arrays of clusters of XY points. XY Graphs take 'array of clusters of XY points' as a single line, and I need to put multiple lines on the graph (in order to change the color), so I use  "Arrays of Clusters of arrays of clusters of XY points". It's messy, but my boss has forbiden me from making any serious changes until I understand all of the existing code, so this is what I work with.
 
The point is, I need to remove the Build Array functions from the for loop in Make Alarm Points.vi, and I need to remove them in a manner that will still allow me to accurately graph the result.
0 Kudos
Message 3 of 9
(3,385 Views)
*sighs* I cannot seem to edit my post...
 
I don't have the slightest Idea what the upper limit on the amount of data is. The 'Graph Code Snippet' runs once a second for as much as an hour, recieving however many points PQ_Wavescope.VI throws out, and ALL of the points need to stay on the graph. CPU usage gets up to 75% after only 30 minutes, so the code has to be smoothed out.  I know the problem is 'Make Alarm Points.vi', because the CPU usage stays under 20% for hours without that VI in the code.
 
I've already tried only sending the new data, but I can't come up with an effective way to keep building all three outputs of 'Make Alarm Points.vi' without causing gaps in the line on the graph display. I don't know HOW to redesign the subVI into a 'LV2 style global', I don't even know what that means; that's why I'm asking for help. Describe what changes I can make to the code, or give me an example and explain how to apply it to my situation.
0 Kudos
Message 4 of 9
(3,369 Views)
Can you attach the subVIs "get range" and "interpolate"?
0 Kudos
Message 5 of 9
(3,342 Views)
oh, yes. My appologies. As you can see, they are both very simple.
Download All
0 Kudos
Message 6 of 9
(3,334 Views)
Alright, I changed Make Alarm Plots.vi. It now creates arrays of the maximum possible size, uses Replace Array Element in stead of Build Array, and uses Array Subset to strip out the empty positions. The VI produces correct results, but it STILL EATS UP CPU TIME! According to the documentation I have, the implementation for Make Alarm Plots.vi is the best possible solution for reducing memory reallocation issues, so I'm out of ideas.
 
I'm posting the latest version of Make Alarm Plots.vi and the section of code that interacts with this subVI. I've also included a 'base' version of the surronding code.
 
If I use the base version in my very large program, the CPU usage after 1 hour of continously graphing is 31%, which is acceptable for the program's application.
If I use the latest version of Make Alarm Plots.vi in my very large program, the CPU usage after 1 hour of continously graphing is 75%. The problem has to be either Make Alarm Plots.vi or the way I interact with it, but I'm out of possible explanations.
0 Kudos
Message 7 of 9
(3,315 Views)
You are still making the mistake to recalculate the entire array from scratch with each call of the subVI. With each call, you preallocate new arrays with new sizes. At the same time, you're still growing an array in the main VI.
 
All the limits testing needs only be done for the newly arrived data, not for all old data over and over (and over and over....)  again. 😉
 
 
0 Kudos
Message 8 of 9
(3,292 Views)
I don't understand. Which array am I recalculating? which subVI are you refering to, the graph display or Make Alarm Points?
 
PQ-Wavescope produces a small number of points each iteration (the maximum number of points i've seen in a single iteration is 37). I take those points and build them into an array of clusters of XY-points. I then pass this array of 37 elements or less into Make Alarm Points.vi. Once I get the results, I append each output array to each stored array, build the arrays into an array of clusters, and graph the result as an XY Graph.
 
Why hasn't the CPU usage dropped? what other changes can I make to the code that will preserve the functionality and reduce CPU usage?
 
There is one minor thing: both graph code snippets should include a "wait 1000 milliseconds".
0 Kudos
Message 9 of 9
(3,272 Views)