out of memory using a fortran-compiled mex
Show older comments
Hi All,
>>mex rnt_oa3d_mex.f
and got rnt_oa3d_mex.mexa64 without errors.
Then, I run a matlab function "rnt_oa3d" in which rnt_oa3d_mex.mexa64 will be called, but I got a "out of memory" error:
>>[dataout,error,pmap]=rnt_oa3d(lonin,latin,zrin,tracer,lonout,latout,zrout,a,b,''); Error using rnt_oa3d_mex Out of memory. Type HELP MEMORY for your options.
Error in rnt_oa3d (line 50) [t2,error]=rnt_oa3d_mex(lonr,latr,zr,t1, lon,lat,z,pmap,a,b);
The OS of my computer is CentOS 6 with a 64-bit AMD CPU. The mexfunction in the nt_oa3d_mex.f is shown below.
Can anyone help me out? I have no idea where I can debug where the error is from. Thanks.
Li
subroutine mexfunction(nlhs, plhs, nrhs, prhs)
implicit none
C-----------------------------------------------------------------------
C (integer) Replace integer by integer*8 on the DEC Alpha and the
C SGI 64-bit platforms
C
integer*8 plhs(*), prhs(*)
integer*8 x,y,z,datain,xhat,yhat,zhat
integer*8 pmap,dataout,errout,a,b
integer*8 mxGetPr, mxCreateDoubleMatrix
C-----------------------------------------------------------------------
C
! matlab call:
! [dataout,errout]=oaTest(x,y,data,xhat,yhat);
integer nlhs, nrhs, mxGetM, mxGetN
integer m_in, n_in, size,PtIn,PtOut,PtIns,
c PtZin,PtZout
! get address of input arrays
x = mxGetPr(prhs(1))
y = mxGetPr(prhs(2))
z = mxGetPr(prhs(3))
datain = mxGetPr(prhs(4))
xhat = mxGetPr(prhs(5))
yhat = mxGetPr(prhs(6))
zhat = mxGetPr(prhs(7))
pmap = mxGetPr(prhs(8))
a = mxGetPr(prhs(9))
b = mxGetPr(prhs(10))
! set output matrix according to sizes of Sn (3)
m_in = mxGetM(prhs(4))
n_in = mxGetN(prhs(4))
PtIn = m_in
PtZin= n_in
m_in = mxGetM(prhs(7))
n_in = mxGetN(prhs(7))
PtOut = m_in
PtZout= n_in
plhs(1) = mxCreateDoubleMatrix(m_in, n_in, 0)
dataout = mxGetPr(plhs(1))
n_in = 1
plhs(2) = mxCreateDoubleMatrix(m_in, n_in, 0)
errout = mxGetPr(plhs(2))
m_in = mxGetM(prhs(8))
n_in = mxGetN(prhs(8))
PtIns = n_in
call oa_ex(%val(x), %val(y),%val(z),%val(datain),
c %val(xhat),%val(yhat),%val(zhat),
c PtIn,PtOut,PtZin,PtZout,%val(dataout),
c %val(errout),%val(a), %val(b),
c PtIns, %val(pmap))
return
end
Accepted Answer
More Answers (2)
Jan
on 18 Jun 2013
0 votes
You can either use a debugger to examine the fortran code oder place some commands to display messages until you find the command, which tries to create a variable, which does not fit into the available memory.
But then I guess, that your somputer simply does not habe enough memory installed to solve your problem. Then different strategies can be applied:
- Install more RAM.
- Clear variables, which are not used anymore.
- Install even more RAM.
- A proper pre-allocation reduces the memory fragmentation.
- Use smaller data types when possible (single instead of double, etc)
- You are using a 64 bit system already, so I omit this as a tip.
- But installing as much RAM as you can afford is the best solution.
Nothing can compete with real and free RAM. I've learned this is the day of my 1kB ZX81, and even the expensive upgrade to 16 kB did not allow the programmers to waste any byte.
Qiang
on 18 Jun 2013
0 votes
Categories
Find more on Fortran Source MEX Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!