LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Node inside loop - Out of memory

Solved!
Go to solution

Hi everyone,

 

I have a Mathscript node inside a subVI that is called inside a for loop. After some iterations of the loop I run out of memory. Therefore I added another Mathcript node with the "clear" function outside the subVI, hoping that after I get the variables from the node I could clear the memory of the Mathscript, but it doesn't work, it still runs out of memory.  Does someone know how can one remove variables from Mathscript node from memory, once they have been saved in the Labview variables? Thanks in advance.

 

memory.png

 

 

0 Kudos
Message 1 of 9
(3,231 Views)

What does the mathscript code do? It would probably more efficient to program it in pure LabVIEW.

What are "LabVIEW variables"?

can you show us a slightly larger section of code, preferably attach the entire subVI.

What does your picture represent? Does the subVI shown contain the mathscript code? What happens first?

What happens to all the 2D arrays at the loop boundary? Do they possibly autoindex into 3D arrays?

How big are these arrays?

0 Kudos
Message 2 of 9
(3,219 Views)

Hello Altenbach,

 

thanks for your answer. This is a code I used to run in Matlab script node but I had problems of slowness, and I just rewrote it to Mathscript node.  It is inside a subVI because I didn't want to make the general VI "big". Inside the subVI there's only the call to the Mathscript node. When I ran this with Matlab script node I didn't receive the out-of-memory error because the Matlab server would restart in each call.

 

In the pic you can see another example. In this example I would like to know how to delete from the Mathscript node the variable "A" and "B", but after the output A has been read. I would like to know how to delete the variables inside the Mathscript node after each iteration. The real code I have inside the node structure is a lot of matrix and vector multiplications (and element-wise multiplication).

 

 

loops.png

Thanks

 

0 Kudos
Message 3 of 9
(3,210 Views)

If you had performance problems using matlab script, I seriously doubt you would get better performance using mathscript. What gave you this idea?

 

You still haven't explain what the code actually does.

 

In a perfect world, Mathscript will re-use the same memory for each call, which would be much more efficient than deallocate/reallocate every time. Do the array sizes change with every call? What are the sizes?

 

What's the point of the local variable. It makes no sense in the current code. Also, why does the indicator needs to be updated in the innermost loop?

 

0 Kudos
Message 4 of 9
(3,203 Views)

What is going to be driving these loops? Right now the outer two loops will do nothing (or at least nothing useful) and the inner loop will llikely generate the same results everytime.

 

Do you have the N terminals of any of these loops wired? If so where is the number coming from?

 

One of the most common causes of an out of memory is a for loop that is autoindexing an output and the N value is calculated from floating point numbers. What happens is the calculation fails resulting in NaN or Inf (both valid floating point values). When these values hit the N terminal they are converted to I32s -- really really large I32s with the result that LabVIEW tries to preallocate more ram than exists on the planet and promptly blows up. Uh labVIEW that is, not the planet...

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 9
(3,199 Views)

@mikeporter wrote:

One of the most common causes of an out of memory is a for loop that is autoindexing an output and the N value is calculated from floating point numbers.


I doubt that that's the problem here because it seems to work by substituting matlab script. I think the problem is deeper.

0 Kudos
Message 6 of 9
(3,190 Views)

thanks to both for your answers. The code ran in matlab would take miliseconds, but when called from Labview it took like 15 seconds. That's why I canged, it was a problem with communication/servers between my Labview and my Matlab.

 

The second picture was just to explain what I meant with labview variables. I meant the nodes outputs:I just want to delete all the variables from the node once the variables are read in the outputs. Actually please ignore the two outer loops, the question would still be the same if I had only the most inner loop.

 

The local variable is in my real VI a global variable, because I then call the values from other VIs (also ignore the two outer loops, because usually they will run only 1 time.)

 

To summarize. Is it possible to delete the variables from the mathscript node once they have been read by the outputs?

 

Thanks again

0 Kudos
Message 7 of 9
(3,183 Views)

I managed to solve the mistake by adding the function

 

real( )

 

making the square and inverse matrices doubles. This matrices were used in lots of calculations so now it uses much less memory.

 

For now everything is good, but I would still like to know the answer, for the future, if I have to use bigger datasets.

 

Another question that would resolve this would be: someone knows how to delete all variables except for some of them? I would delete everything except for the variables that are read by the outputs. Right now it's not urgent, though.

0 Kudos
Message 8 of 9
(3,127 Views)
Solution
Accepted by topic author Gabi11

You still don't really give any useful information to troubleshoot the problem. As I exaplained, constantly deleting datasets just to reallocate them in the next iteration is typically ill adviced, because it just causes more performance problems and even memory fragmentation. It is better to operate in-place as much as possible.

Who wrote the matlab code? Maybe it is very inefficient? What does it do? Maybe rewriting it in LabVIEW would gain you significant performance.

0 Kudos
Message 9 of 9
(3,109 Views)