From: Richard Messeder on
I am not skilled with MATLAB, though I have programming experience to a limited degree in various languages. I am writing to both COMSOL and MATLAB to see if there is a solution to this problem.

I am interfacing MATLAB for the first time with an external product, COMSOL. With COMSOL active, I make calls to it that are provided when COMSOL invokes the MATLAB program and connects to it:
Ex = postinterp (xfem, 'Ex_es', pxyz');
Ey = postinterp (xfem, 'Ey_es', pxyz');
Ez = postinterp (xfem, 'Ez_es', pxyz');

Each invocation of postinterp () apparently allocates ~60MB of memory. I used the Windows Performance and Processes monitors to show me how much memory is allocated, which process seems to claim the memory allocated (MATLAB, in this case), and how long the memory is allocated. The memory allocation is a show-stopper considering my needs. 60MB x 3D x 10 steps ~= 1.8 GB !! of system memory allocated.

I observed that the memory allocation hung about "forever", UNLESS I clicked on various UI elements in MATLAB. I eventually found that by clicking on several editor tabs for various files that were open (changing the focus) I could get the memory released.

I trolled the web looking for hints that might help me, and I cobbled together code segments that look like this (in part):
while (tmemstatsval (2) < 1900) % this is the MB of free memory available
set (0,'CurrentFigure',h);
title = jEditor.getTitle;
currentFilename = char (title.replaceFirst ('Editor - ', ''));
set (jEditor, 'Title', char(title));
commandwindow;
jEditor.toFront;
jEditor.transferFocus();
jEditor.transferFocus();
jEditor.transferFocus();

tmemstats = regexp (evalc ('feature(''memstats'')'), '(\w*) MB', 'match');
tmemstatsval = sscanf ([tmemstats{:}],'%f MB');
end

I don't claim that any of this is neat, efficient, programmatically relevant, or defensible beyond the fact that it seems to work (in conjunction with other code segments in the same block). I have not tried to eliminate any lines of code to see if I can keep the effect with fewer statements.

All of my code and relevant images are here:
http://pubpages.unh.edu/~rlo9/MMS/

In particular, the image ending "memory.usage.cycles.1.180s.no_int.tif" shows the memory allocation situation before my code cobbling efforts, and the image ending "memory.usage.cycles.auto.2.tif" shows the results. Note that it still "seems" to take 6 s to release all the memory, which I suspect has something to do with the COMSOL-MATLAB interface, but I really don't know.

This is a simple model in COMSOL and MATLAB, but I am using it as a proof of concept, and there is very large project that depends on the success of working out the bugs in the overall process. I'll be happy to explain anything about the current model and any design decisions that I have made. Please don't hesitate to criticise or ask questions ;-)

Kind regards,
~Rich~
 | 
Pages: 1
Prev: Function in Matlab
Next: POWER ELECTRONICS