Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
gfortran 4.4 and mex files on Linux

Subject: gfortran 4.4 and mex files on Linux

From: Ali Yurukoglu

Date: 22 Dec, 2009 22:35:05

Message: 1 of 7

I have some fortran mex files that work beautifully when compiled in 64 bit vista with ifort (version 11.1).

The same mex files seg fault when compiled with gfortran 4.4 and run on linux. According to the gnu debugger, the seg fault is in the gateway routine at one of the mex commands.

Has anyone had this problem? I know gfortran 4.4 is not supported officially (neither is ifort 11.1), but I am using the %val construct. As I understand, versions of gfortran which are officially supported by TMW don't understand %val.

thank you for your help!

Subject: gfortran 4.4 and mex files on Linux

From: James Tursa

Date: 23 Dec, 2009 08:27:04

Message: 2 of 7

"Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgrhip$eb5$1@fred.mathworks.com>...
> I have some fortran mex files that work beautifully when compiled in 64 bit vista with ifort (version 11.1).
>
> The same mex files seg fault when compiled with gfortran 4.4 and run on linux. According to the gnu debugger, the seg fault is in the gateway routine at one of the mex commands.
>
> Has anyone had this problem? I know gfortran 4.4 is not supported officially (neither is ifort 11.1), but I am using the %val construct. As I understand, versions of gfortran which are officially supported by TMW don't understand %val.
>
> thank you for your help!

Can you post a minimal code that duplicates the problem?

James Tursa

Subject: gfortran 4.4 and mex files on Linux

From: Ali Yurukoglu

Date: 23 Dec, 2009 17:32:21

Message: 3 of 7

Yes, well the seg fault happens with the (compiled mex file) of timestwo.F provided as a matlab example even. Here is the output from the compiler.

Then I do a=timestwo(3) and I get a seg fault.

mex timestwo.F -v
-> mexopts.sh sourced from directory (DIR = .)
   FILE = /somepath/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /path/software/matlab-2009b
-> CC = gcc44
-> CC flags:
         CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
         CDEBUGFLAGS = -g
         COPTIMFLAGS = -O -mtune=native -DNDEBUG
         CLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
         arguments = -DMX_COMPAT_32
-> CXX = g++44
-> CXX flags:
         CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
         CXXDEBUGFLAGS = -g
         CXXOPTIMFLAGS = -O -mtune=native -DNDEBUG
         CXXLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments = -DMX_COMPAT_32
-> FC = gfortran44
-> FC flags:
         FFLAGS = -fexceptions -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS = -g
         FOPTIMFLAGS = -O -mtune=native
         FLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments = -DMX_COMPAT_32
-> LD = gfortran44
-> Link flags:
         LDFLAGS = -pthread -shared -Wl,--version-script,/path/software/matlab-2009b/extern/lib/glnxa64/fexport.map -Wl,--no-undefined
         LDDEBUGFLAGS = -g
         LDOPTIMFLAGS = -O -mtune=native
         LDEXTENSION = .mexa64
         arguments =
-> LDCXX =
-> Link flags:
         LDCXXFLAGS =
         LDCXXDEBUGFLAGS =
         LDCXXOPTIMFLAGS =
         LDCXXEXTENSION =
         arguments =
----------------------------------------------------------------


Warning: You are using gcc version "4.4.0". The earliest gcc version supported
         with mex is "4.1". The latest version tested for use with mex is "4.2".
         To download a different version of gcc, visit http://gcc.gnu.org

-> gfortran44 -c -I/path/software/matlab-2009b/extern/include -I/path/software/matlab-2009b/simulink/include -fexceptions -fPIC -fno-omit-frame-pointer -DMX_COMPAT_32 -O -mtune=native "timestwo.F"

-> gfortran44 -O -mtune=native -pthread -shared -Wl,--version-script,/path/software/matlab-2009b/extern/lib/glnxa64/fexport.map -Wl,--no-undefined -o "timestwo.mexa64" timestwo.o -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm


I don't understand every option in the sh file, so perhaps it is one of those. Before going one by one, I am hoping to find someone who can see easily what the problem is.

thank you



"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hgsk8o$mdi$1@fred.mathworks.com>...
> "Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgrhip$eb5$1@fred.mathworks.com>...
> > I have some fortran mex files that work beautifully when compiled in 64 bit vista with ifort (version 11.1).
> >
> > The same mex files seg fault when compiled with gfortran 4.4 and run on linux. According to the gnu debugger, the seg fault is in the gateway routine at one of the mex commands.
> >
> > Has anyone had this problem? I know gfortran 4.4 is not supported officially (neither is ifort 11.1), but I am using the %val construct. As I understand, versions of gfortran which are officially supported by TMW don't understand %val.
> >
> > thank you for your help!
>
> Can you post a minimal code that duplicates the problem?
>
> James Tursa

Subject: gfortran 4.4 and mex files on Linux

From: Ali Yurukoglu

Date: 29 Dec, 2009 00:28:19

Message: 4 of 7

Just an update: timestwo works when I run it in gnu debugger, but seg faults when I run it in matlab.

I modified timestwo and renamed it timestwo.F90

#include "fintrf.h"

      subroutine mexFunction(nlhs, plhs, nrhs, prhs)
      mwpointer plhs(*), prhs(*)
      mwpointer mxGetPr, mxCreateDoubleMatrix
      mwpointer x, y
      integer nlhs, nrhs
      integer mxIsNumeric
      mwsize mxGetM, mxGetN
      mwsize m, n, size

      x = mxGetPr(prhs(1))

      m = mxGetM(prhs(1))
      n = mxGetN(prhs(1))
      size = m*n

      plhs(1) = mxCreateDoubleMatrix(m,n,0)
      y = mxGetPr(plhs(1))

      call timestwo(%val(y), %val(x),m,n)


      return
      end

      subroutine timestwo(y, x, m, n)
implicit none
mwsize m, n
      double precision x(m,n), y(m,n)
integer i,j

do i=1,m
do j=1,n
      y(i,j) = 2.0 * x(i,j)
end do
end do

      end




"Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgtk75$7tf$1@fred.mathworks.com>...
> Yes, well the seg fault happens with the (compiled mex file) of timestwo.F provided as a matlab example even. Here is the output from the compiler.
>
> Then I do a=timestwo(3) and I get a seg fault.
>
> mex timestwo.F -v
> -> mexopts.sh sourced from directory (DIR = .)
> FILE = /somepath/mexopts.sh
> ----------------------------------------------------------------
> -> MATLAB = /path/software/matlab-2009b
> -> CC = gcc44
> -> CC flags:
> CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
> CDEBUGFLAGS = -g
> COPTIMFLAGS = -O -mtune=native -DNDEBUG
> CLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
> arguments = -DMX_COMPAT_32
> -> CXX = g++44
> -> CXX flags:
> CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
> CXXDEBUGFLAGS = -g
> CXXOPTIMFLAGS = -O -mtune=native -DNDEBUG
> CXXLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
> arguments = -DMX_COMPAT_32
> -> FC = gfortran44
> -> FC flags:
> FFLAGS = -fexceptions -fPIC -fno-omit-frame-pointer
> FDEBUGFLAGS = -g
> FOPTIMFLAGS = -O -mtune=native
> FLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
> arguments = -DMX_COMPAT_32
> -> LD = gfortran44
> -> Link flags:
> LDFLAGS = -pthread -shared -Wl,--version-script,/path/software/matlab-2009b/extern/lib/glnxa64/fexport.map -Wl,--no-undefined
> LDDEBUGFLAGS = -g
> LDOPTIMFLAGS = -O -mtune=native
> LDEXTENSION = .mexa64
> arguments =
> -> LDCXX =
> -> Link flags:
> LDCXXFLAGS =
> LDCXXDEBUGFLAGS =
> LDCXXOPTIMFLAGS =
> LDCXXEXTENSION =
> arguments =
> ----------------------------------------------------------------
>
>
> Warning: You are using gcc version "4.4.0". The earliest gcc version supported
> with mex is "4.1". The latest version tested for use with mex is "4.2".
> To download a different version of gcc, visit http://gcc.gnu.org
>
> -> gfortran44 -c -I/path/software/matlab-2009b/extern/include -I/path/software/matlab-2009b/simulink/include -fexceptions -fPIC -fno-omit-frame-pointer -DMX_COMPAT_32 -O -mtune=native "timestwo.F"
>
> -> gfortran44 -O -mtune=native -pthread -shared -Wl,--version-script,/path/software/matlab-2009b/extern/lib/glnxa64/fexport.map -Wl,--no-undefined -o "timestwo.mexa64" timestwo.o -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
>
>
> I don't understand every option in the sh file, so perhaps it is one of those. Before going one by one, I am hoping to find someone who can see easily what the problem is.
>
> thank you
>
>
>
> "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hgsk8o$mdi$1@fred.mathworks.com>...
> > "Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgrhip$eb5$1@fred.mathworks.com>...
> > > I have some fortran mex files that work beautifully when compiled in 64 bit vista with ifort (version 11.1).
> > >
> > > The same mex files seg fault when compiled with gfortran 4.4 and run on linux. According to the gnu debugger, the seg fault is in the gateway routine at one of the mex commands.
> > >
> > > Has anyone had this problem? I know gfortran 4.4 is not supported officially (neither is ifort 11.1), but I am using the %val construct. As I understand, versions of gfortran which are officially supported by TMW don't understand %val.
> > >
> > > thank you for your help!
> >
> > Can you post a minimal code that duplicates the problem?
> >
> > James Tursa

Subject: gfortran 4.4 and mex files on Linux

From: Ali Yurukoglu

Date: 29 Dec, 2009 00:46:05

Message: 5 of 7

Sorry for the multiple posts. Its not that it works only in Gnu debugger, but it turns out it works sometimes and sometimes not.

I can open matlab, mex the file, do a=timestwo(5) and it might work. Close matlab, open matlab, mex the file, do the same command as before, and seg fault.

The reason I thought it was gnu debugger which helped was just that I got lucky twice in gnu debugger.



"Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hhbif3$crc$1@fred.mathworks.com>...
> Just an update: timestwo works when I run it in gnu debugger, but seg faults when I run it in matlab.
>
> I modified timestwo and renamed it timestwo.F90
>
> #include "fintrf.h"
>
> subroutine mexFunction(nlhs, plhs, nrhs, prhs)
> mwpointer plhs(*), prhs(*)
> mwpointer mxGetPr, mxCreateDoubleMatrix
> mwpointer x, y
> integer nlhs, nrhs
> integer mxIsNumeric
> mwsize mxGetM, mxGetN
> mwsize m, n, size
>
> x = mxGetPr(prhs(1))
>
> m = mxGetM(prhs(1))
> n = mxGetN(prhs(1))
> size = m*n
>
> plhs(1) = mxCreateDoubleMatrix(m,n,0)
> y = mxGetPr(plhs(1))
>
> call timestwo(%val(y), %val(x),m,n)
>
>
> return
> end
>
> subroutine timestwo(y, x, m, n)
> implicit none
> mwsize m, n
> double precision x(m,n), y(m,n)
> integer i,j
>
> do i=1,m
> do j=1,n
> y(i,j) = 2.0 * x(i,j)
> end do
> end do
>
> end
>
>
>
>
> "Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgtk75$7tf$1@fred.mathworks.com>...
> > Yes, well the seg fault happens with the (compiled mex file) of timestwo.F provided as a matlab example even. Here is the output from the compiler.
> >
> > Then I do a=timestwo(3) and I get a seg fault.
> >
> > mex timestwo.F -v
> > -> mexopts.sh sourced from directory (DIR = .)
> > FILE = /somepath/mexopts.sh
> > ----------------------------------------------------------------
> > -> MATLAB = /path/software/matlab-2009b
> > -> CC = gcc44
> > -> CC flags:
> > CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
> > CDEBUGFLAGS = -g
> > COPTIMFLAGS = -O -mtune=native -DNDEBUG
> > CLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
> > arguments = -DMX_COMPAT_32
> > -> CXX = g++44
> > -> CXX flags:
> > CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
> > CXXDEBUGFLAGS = -g
> > CXXOPTIMFLAGS = -O -mtune=native -DNDEBUG
> > CXXLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
> > arguments = -DMX_COMPAT_32
> > -> FC = gfortran44
> > -> FC flags:
> > FFLAGS = -fexceptions -fPIC -fno-omit-frame-pointer
> > FDEBUGFLAGS = -g
> > FOPTIMFLAGS = -O -mtune=native
> > FLIBS = -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
> > arguments = -DMX_COMPAT_32
> > -> LD = gfortran44
> > -> Link flags:
> > LDFLAGS = -pthread -shared -Wl,--version-script,/path/software/matlab-2009b/extern/lib/glnxa64/fexport.map -Wl,--no-undefined
> > LDDEBUGFLAGS = -g
> > LDOPTIMFLAGS = -O -mtune=native
> > LDEXTENSION = .mexa64
> > arguments =
> > -> LDCXX =
> > -> Link flags:
> > LDCXXFLAGS =
> > LDCXXDEBUGFLAGS =
> > LDCXXOPTIMFLAGS =
> > LDCXXEXTENSION =
> > arguments =
> > ----------------------------------------------------------------
> >
> >
> > Warning: You are using gcc version "4.4.0". The earliest gcc version supported
> > with mex is "4.1". The latest version tested for use with mex is "4.2".
> > To download a different version of gcc, visit http://gcc.gnu.org
> >
> > -> gfortran44 -c -I/path/software/matlab-2009b/extern/include -I/path/software/matlab-2009b/simulink/include -fexceptions -fPIC -fno-omit-frame-pointer -DMX_COMPAT_32 -O -mtune=native "timestwo.F"
> >
> > -> gfortran44 -O -mtune=native -pthread -shared -Wl,--version-script,/path/software/matlab-2009b/extern/lib/glnxa64/fexport.map -Wl,--no-undefined -o "timestwo.mexa64" timestwo.o -Wl,-rpath-link,/path/software/matlab-2009b/bin/glnxa64 -L/path/software/matlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
> >
> >
> > I don't understand every option in the sh file, so perhaps it is one of those. Before going one by one, I am hoping to find someone who can see easily what the problem is.
> >
> > thank you
> >
> >
> >
> > "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hgsk8o$mdi$1@fred.mathworks.com>...
> > > "Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgrhip$eb5$1@fred.mathworks.com>...
> > > > I have some fortran mex files that work beautifully when compiled in 64 bit vista with ifort (version 11.1).
> > > >
> > > > The same mex files seg fault when compiled with gfortran 4.4 and run on linux. According to the gnu debugger, the seg fault is in the gateway routine at one of the mex commands.
> > > >
> > > > Has anyone had this problem? I know gfortran 4.4 is not supported officially (neither is ifort 11.1), but I am using the %val construct. As I understand, versions of gfortran which are officially supported by TMW don't understand %val.
> > > >
> > > > thank you for your help!
> > >
> > > Can you post a minimal code that duplicates the problem?
> > >
> > > James Tursa

Subject: gfortran 4.4 and mex files on Linux

From: Bastian

Date: 26 Jan, 2010 13:54:04

Message: 6 of 7

I just came across this topic since I am experiencing a similar problem. Did you find a solution?

Subject: gfortran 4.4 and mex files on Linux

From: Thomas Clark

Date: 26 Jan, 2010 22:01:38

Message: 7 of 7

I'm not an expert, but a couple of suggestions:

1. I don't use %val, but I've had a lot of success with gfortran 4.3 in linux. Maybe try that instead of 4.4?

2. I had a problem with arrays a while ago that had exactly the same symptoms. It turned out to be a heap/stack problem. I was using Intel FC at the time, and fixed it with the -heap-arrays compiler flag, to force arrays onto the heap instead of the stack.

Tom

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us