Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Mex file error with large array
Posted:
Mar 20, 2013 5:46 PM


"m " <mathdu69180@hotmail.fr> wrote in message <kic86i$ppm$1@newscl01ah.mathworks.com>... > Hello, > > I have two cubes of data and I want to make a linear regression between two little cubes (one in each big cube of data), so I make this code (example here) : X_pad and Y_pad are our data but with a padding around the cube to compute the linear regression everywhere. > So I have to do three loops and I make a mex file in Fortran to do it. > > But when I run it, with, for example data with this size : 1500x300x800, I have this error : > > 'test.mexa64': test.mexa64: cannot map zerofill pages: Cannot allocate memory > > Do you know what that mean and how to fix it ? > > Here is the interface function :
(snip)
> integer*4 numel > parameter(numel = 9000000000) > real*8 x(numel), y(numel), z(numel), sized(numel), win(numel)
You do NOT want to do what you are doing above. The variables x, y, z, sized, and win are LOCAL variables, meaning they will in all likelihood get their memory from the stack which has a limited size. So you are probably overflowing your stack. Particularly for large variables you need to be getting this memory from the heap, not the stack. So make these variables allocatable instead. E.g.,
integer*4 numel, istat parameter(numel = 9000000000) real*8, allocatable :: x(:), y(:), z(:), sized(:), win(:) : allocate(x(numel),stat=istat) if( istat /= 0 ) then ! take appropriate action endif : etc for y, z, sized, win
Then at the end of your code deallocate them.
Another option to consider is this F95/MATLAB interface package which allows you to point directly at MATLAB variable memory, often avoiding the need to copy memory:
http://www.mathworks.com/matlabcentral/fileexchange/25934fortran95interfacetomatlabapiwithextras
James Tursa



