From: Eric Tittley on
Hey all,

I have a problem running on a 64bit Linux system:
Linux 2.6.26-2-amd64 #1 SMP Tue Mar 9 22:29:32 UTC 2010 x86_64 GNU/Linux

Matlab is 64bit: Version 7.8.0.347 (R2009a) 64-bit (glnxa64)

My problem is that I cannot get Fortran code to run when using -largeArrayDims.

I used the timestwo.F from matlab78/extern/examples/refbook/ as a test function. Obviously it doesn't need large array access, but if it can't compile, then there is a more serious problem.

mex timestwo.F WORKS
mex -largeArrayDims timestwo.F FAILS
mex timestwo.c WORKS
mex -largeArrayDims timestwo.c WORKS

By "WORKS" I mean that:
>> X=5; timestwo(X)
ans =
10

By "FAIL", I mean:
>> X=5; timestwo(X)
??? Error using ==> timestwo
Too many output arguments.

which is really just an indication that the test (nlhs .gt. 1) is failing since it (probably) thinks nlhs is a long integer, when matlab is actually passing it a 4-byte integer.

nlhs is declared as:
mwsize nlhs, nrhs

and with -largeArrayDims, mwsize is integer*8

Could it be the compiler version? I'm using:
GNU Fortran (Debian 4.3.2-1.1) 4.3.2

Here are details of the compilation:

mex -V -largeArrayDims timestwo.F
-> gfortran -c -I/opt/matlab78/extern/include -fexceptions -fPIC -fno-omit-frame-pointer -O3 "timestwo.F"
-> gfortran -O3 -pthread -shared -Wl,--version-script,/opt/matlab78/extern/lib/glnxa64/fexport.map -Wl,--no-undefined -o "timestwo.mexa64" timestwo.o -Wl,-rpath-link,/opt/matlab78/bin/glnxa64 -L/opt/matlab78/bin/glnxa64 -lmx -lmex -lmat -lm

mex -V timestwo.F
-> gfortran -c -I/opt/matlab78/extern/include -fexceptions -fPIC -fno-omit-frame-pointer -DMX_COMPAT_32 -O3 "timestwo.F"
-> gfortran -O3 -pthread -shared -Wl,--version-script,/opt/matlab78/extern/lib/glnxa64/fexport.map -Wl,--no-undefined -o "timestwo.mexa64" timestwo.o -Wl,-rpath-link,/opt/matlab78/bin/glnxa64 -L/opt/matlab78/bin/glnxa64 -lmx -lmex -lmat -lm

The only difference is the inclusion of "-DMX_COMPAT_32" when -largeArrayDims is not used. That switches the size of pointers and integers that are used to indicate sizes of arrays.

Any ideas?

Cheers,
Eric
From: James Tursa on
"Eric Tittley" <3ert(a)delete.this.and.the.3.roe.ac.uk> wrote in message <hu36l0$gt0$1(a)fred.mathworks.com>...
>
> mex timestwo.F WORKS
> mex -largeArrayDims timestwo.F FAILS
> mex timestwo.c WORKS
> mex -largeArrayDims timestwo.c WORKS
>
> By "WORKS" I mean that:
> >> X=5; timestwo(X)
> ans =
> 10
>
> By "FAIL", I mean:
> >> X=5; timestwo(X)
> ??? Error using ==> timestwo
> Too many output arguments.
>
> which is really just an indication that the test (nlhs .gt. 1) is failing since it (probably) thinks nlhs is a long integer, when matlab is actually passing it a 4-byte integer.
>
> nlhs is declared as:
> mwsize nlhs, nrhs

Here is the signature for mexFunction:

subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer*4 nlhs, nrhs
mwPointer plhs(*), prhs(*)

nlhs and nrhs should be integer*4, not mwSize.

James Tursa
From: Eric Tittley on
"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hu392d$2dq$1(a)fred.mathworks.com>...
> "Eric Tittley" <3ert(a)delete.this.and.the.3.roe.ac.uk> wrote in message <hu36l0$gt0$1(a)fred.mathworks.com>...
> >
> > mex timestwo.F WORKS
> > mex -largeArrayDims timestwo.F FAILS
> > mex timestwo.c WORKS
> > mex -largeArrayDims timestwo.c WORKS
> >
> > By "WORKS" I mean that:
> > >> X=5; timestwo(X)
> > ans =
> > 10
> >
> > By "FAIL", I mean:
> > >> X=5; timestwo(X)
> > ??? Error using ==> timestwo
> > Too many output arguments.
> >
> > which is really just an indication that the test (nlhs .gt. 1) is failing since it (probably) thinks nlhs is a long integer, when matlab is actually passing it a 4-byte integer.
> >
> > nlhs is declared as:
> > mwsize nlhs, nrhs
>
> Here is the signature for mexFunction:
>
> subroutine mexFunction(nlhs, plhs, nrhs, prhs)
> integer*4 nlhs, nrhs
> mwPointer plhs(*), prhs(*)
>
> nlhs and nrhs should be integer*4, not mwSize.
>
> James Tursa

Thanks James!

I just figured that out and was about to post a fix to my own problem. The example provided by Mathworks is in error (albeit, it was designed to demonstrate other aspects of mex programming).

Cheers,
Eric
 | 
Pages: 1
Prev: Integration of matrix data
Next: DIDO package