Duke-UNC Brain Imaging and Analysis Center
BIAC Forums | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password   Forgot your Password?
 All Forums
 Support Forums
 Analysis Software Support
 MATLAB out of memory
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dvsmith
Advanced Member

USA
218 Posts

Posted - Feb 27 2010 :  7:03:51 PM  Show Profile  Visit dvsmith's Homepage  Reply with Quote
I'm having memory issues trying to load some high-res fMRI data (128 x 128 x 30 x 344; file size is about 200 MBs). I don't understand why MATLAB and the BIAC tools can't work with this since I have 3.5 GBs of RAM on my work computer.

>> x = readmr('run1.nii.gz')
??? Error using ==> readmr
Error using ==> zeros
Out of memory. Type HELP MEMORY for your options.

I can load the file on my MacBook Pro (4 GBs of RAM), but then I get the memory error when I try to view it with showsrs2.

>> x = readmr('run1.nii.gz')

x =

data: [4-D double]
info: [1x1 struct]

>> showsrs2(x)
??? Error using ==> showsrs2 at 505
Out of memory. Type HELP MEMORY for your options.

Any ideas?

Thanks,
David

petty
BIAC Staff

USA
453 Posts

Posted - Feb 28 2010 :  6:30:20 PM  Show Profile  Reply with Quote
Is your work computer a window's box?

Windows throttles the available memory down to 2GB of ram with 32-bit ... and even if its not a 32-bit system, matlab is likely the 32-bit install.

Check to see if you can load it on the interactive node ... its 64bit, running 64bit matlab. I was able to do this on my linux box, which is a similar architecture.

Also, do you have you pro running the 64bit version of the OS, and/or the 64bit matlab?

In snow leopard you have to specifically set this, but to check, look at the software tab of the system-profiler ...
"64-bit Kernel and Extensions: Yes"

You should see this if you are running 64. If you are not:

Edit the file:

/Library/Preferences/SystemConfiguration/com.apple.Boot.plist

Insert arch=x86_64 into the Kernel Flags field.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Kernel</key>
	<string>mach_kernel</string>
	<key>Kernel Flags</key>
	<string>arch=x86_64</string>
</dict>
</plist>

Go to Top of Page

dvsmith
Advanced Member

USA
218 Posts

Posted - Mar 01 2010 :  09:57:47 AM  Show Profile  Visit dvsmith's Homepage  Reply with Quote
Thanks for the info, Chris. Yeah, my work computer in Scott's lab is a Windows computer (and it's all 32-bit). I also currently have everything on my MacBook Pro set up to be 32-bit (e.g., "64-bit Kernel and Extensions: No"), but it looks like upgrading to 64-bit would be fairly trivial (assuming it doesn't break some of the other apps already have on there).

I think there's still something I don't understand about the memory issues. My intuition was that something 200 MBs should be easily handled with 2000 MBs of RAM. I guess Matlab is already using a significant chunk of that, so maybe I don't have enough when I try to load the high-res data file.

David
Go to Top of Page

james.kragel
Starting Member

USA
9 Posts

Posted - Mar 01 2010 :  10:18:25 AM  Show Profile  Reply with Quote
If you want to see the largest available contiguous block of memory on 32-bit windows, you can use the following:

feature memstats

There are some other utilities that have been developed that look for ways to improve your memory on 32-bit windows, but most of them just check if you're use /3GB in your boot config, and if you have any dlls running that fragment memory.

MATLAB should easily be able to load a 200MB image, unless other things are loaded to memory...
Go to Top of Page

syam.gadde
BIAC Staff

USA
421 Posts

Posted - Mar 01 2010 :  11:15:41 AM  Show Profile  Reply with Quote
If you consider that MATLAB's native format is double-precision floating point (8 bytes per voxel), it's easier to imagine why it runs out of memory. Things may have changed recently, but for the longest time, many operations were only supported on double-precision floating point matrices, so one copy of your 128x128x30x344 data actually requires 1.3GB of memory. In addition, there used to be basically no in-place matrix operation in MATLAB -- everything required a copy (followed generally by a deletion). So even if you were just adding a constant to the above data, you needed to make a copy of it, add to it, and then if you assign the new data to the old name, then the old memory gets freed up. If you have a limit of 2GB of memory, it's easy to see why you might hit the limit with large-ish numbers of higher-resolution images.
Go to Top of Page

dvsmith
Advanced Member

USA
218 Posts

Posted - Mar 01 2010 :  3:19:21 PM  Show Profile  Visit dvsmith's Homepage  Reply with Quote
Jim: memstats appears to be unrecognized. Is that the right feature?
>> feature memstats
??? Error using ==> feature
An unknown feature was specified

Syam: That makes a lot more sense. The native precision is int-16 (signed), so going up to double floating point would make it a lot bigger in Matlab. I didn't know about the copying aspect in Matlab, and I'm not sure if that's still in place. As these sorts of image matrices contain many zeros -- so maybe they're technically sparse matrices? -- would it be possible to load the data differently?


For now, I think I'll just use FSLview or upgrade my system to 64-bit.

Thanks,
David
Go to Top of Page

james.kragel
Starting Member

USA
9 Posts

Posted - Mar 01 2010 :  3:34:46 PM  Show Profile  Reply with Quote
That's the correct feature. It should work in any version of MATLAB newer than 7.0, so maybe you are using an old version?

If you're using 2008a or newer, you can just use the function 'memory' to get similar but less detailed information.
Go to Top of Page

dvsmith
Advanced Member

USA
218 Posts

Posted - Mar 01 2010 :  4:09:54 PM  Show Profile  Visit dvsmith's Homepage  Reply with Quote
It appears to be a Window vs Mac thing.

"feature memstats" works on my Windows Machine, but not my Mac. Both Matlabs are newer than 7.0.

The memory function apparently doesn't work on Macs, so I'll look for an equivalent...

Thanks,
David
Go to Top of Page

charles.michelich
BIAC Alum

USA
183 Posts

Posted - Mar 07 2010 :  12:54:07 AM  Show Profile  Reply with Quote
There should be no need to change to the 64-bit kernel on your Mac. Mac OS X can run both 32-bit and 64-bit applications using either the 32-bit or 64-bit kernel. Most of the applications on my computer are 64-bit, but I am running the 32-bit kernel. If you need to install a kernel extension, then the kernel extension must match the kernel you are running (e.g. 32-bit kernel extensions only work with 32-bit kernels and 64-bit kernel extensions only work with 64-bit kernels). However, I don't think that MATLAB uses any kernel extensions.

According to the system requirements, 64-bit MATLAB runs on all Intel-based Mac with a Core 2 or later CPU. You can select which version to use when you install or when you launch.

If you would like to read more about 64-bit support on Mac OS X, there are some good explanations at Ars Technica
Mac OS X 10.5 Leopard review
Mac OS X 10.6 Snow Leopard review

Enjoy,
Chuck

Edited by - charles.michelich on Mar 07 2010 12:56:17 AM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
BIAC Forums © 2000-2010 Brain Imaging and Analysis Center Go To Top Of Page
This page was generated in 0.41 seconds. Snitz Forums 2000