Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Mex file error with large array
Replies: 1   Last Post: Mar 20, 2013 5:46 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
James Tursa

Posts: 2,071
Registered: 8/5/09
Re: Mex file error with large array
Posted: Mar 20, 2013 5:46 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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 zero-fill 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/25934-fortran-95-interface-to-matlab-api-with-extras

James Tursa



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.