LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview->Matlab->memory bug?

Hello all,

 

I am using  Labview to pass data to Matlab, and get two memory problems with it.

 

1) The array that allocated, never can be deallocated, and still there till vi is closed. (I did all the checks  with a Windows "Task manager")

 

2) Huge spikes in used memory. For example while trying to pass 20 Mega double array (160 MBytes) the spike was reaching 2.2 GBytes of used memory

   ( started a vi with 550 Mega used memory);

 

My be somebody meet these issue before?

 Attaching a vi I used for tests

 

Thanks,

Michael.

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 1 of 8
(3,858 Views)

What you are seeing has nothing to do with Matlab. If you removed the script nodes the VI would behave the same way. You're probably running this on Windows. As stated in the LabVIEW Help:

VI Memory Usage var L_helpType = "STD_ENG"; Dim hasPlayer, playerversion hasPlayer = false playerversion = 10 Do While playerversion > 0 On Error Resume Next hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion))) If hasPlayer = true Then Exit Do playerversion = playerversion - 1 Loop is_FlashVersion = playerversion is_Flash = hasPlayer

On Windows and Linux platforms, data buffers are not normally deallocated unless a VI is closed and removed from memory. Memory is allocated from the operating system as needed, and virtual memory works well on these platforms. Due to fragmentation, the application might appear to use more memory than it really does. As memory is allocated and freed, the application tries to consolidate memory usage so it can return unused blocks to the operating system.

That said, LabVIEW tries to be smart about when data buffers are no longer needed, and it will try to reuse buffers. You can add a Request Deallocation function in your Stop button event case to request a deallocation of memory. Note, however, that this function should be used sparingly. In the long run it reduces efficiency.

 

Also, I don't have Matlab on this computer that I'm on so I can't verify this, but I'm almost certain that the two Matlab script nodes will be independent of each other, meaning that the second script node has no knowledge of the variable "arr". I'll try to verify this tomorrow at work since I have Matlab on my computer at work.

Message 2 of 8
(3,849 Views)

Hi smercurio,

 

Thanks about "Request Deallocation", never meet it before.

Another way  I will try  "call vi by reference" to force it.

About the scripts - it's OK, they are using the same matlab workspace.

 

But the main problem still misterious about the huge spices.

 

thanks.

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 3 of 8
(3,815 Views)

I don't understand what you mean by using Call By Reference. What do you intend to do with this?

 

With respect to the spikes: You're seeing memory allocation due to having to passing the array into Matlab. If you watch the LabVIEW and Matlab processes you will see the memory usage of both go up as the array is being passed from LabVIEW to Matlab. Matlab doesn't handle arrays in the same way as LabVIEW, so Matlab has to store the array its own way. This means extra memory allocation. 

 

Fundamentally, whatever you're trying to do has a critical flaw in that you're passing around these huge arrays. It's exacerbated by the fact that you're trying to do this between LabVIEW and Matlab. What is it that you're trying to accomplish? What are you trying to do in Matlab that you believe you cannot do in LabVIEW?

Message 4 of 8
(3,783 Views)

I thought that by calling the vi by reference i would force it to free the memory that vi allocates, i see that it was wrong (one need two levels of VI's)

Now I just using "Request deallocation".

  It is a headacke  these large arrays.In general it's a 3D array that reshaped to 1D... 

  It seems like at some moment I will drop the idea using "monolite"  3D array and will handle many 2D's at array of queues.

Simple "walkaround" of passing data to Matlab script i did - just save/load binary file.

 

About need of Matlab - there is some 3D processing,and in Matlab one can easy "walk" thru dimensions,IMHO Labview misses it.

 

Thanks ,

Michael.

Message Edited by mishklyar on 09-22-2008 10:58 AM
_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 5 of 8
(3,775 Views)

Well, I don't really know what you mean by "walking through dimensions", unless you're talking about an Outer Limits or Twilight Zone episode. Smiley Very Happy

 

LabVIEW can handle arrays quite well. Perhaps auto-indexing is what you're after? If you indicate exactly what you're trying to do we can suggest how to do it in LabVIEW. altenbach is the "unofficial" "king of arrays" around here, and if he can't find an efficient way to do it in LabVIEW, then it probably can't be done. 

Message 6 of 8
(3,759 Views)

I didn't  see  "Outer Limits" but understand what you mean 🙂 ,

I have two reasons to use matlab,one of them is that my boss used it for something like 15 year  🙂 and he want it so 🙂

The second is : 

     3D FFT                                    - is one line of code.

    FFT over specific dimension    - "    "     "     "    "

    Array and matrix operations is highly optimized,and user friendly (Like DAQ in Labview 🙂   )

 

But probably it can be owerused, so one get 3 lines of code with 20 math operations that very hard to read.

I didn't  large programs at Matlab,so cann't compare it to LV at this scope.

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 7 of 8
(3,755 Views)
No problem. Just trying to help. Smiley Wink
Message 8 of 8
(3,749 Views)