3
votes

I am using gnumex in Matlab in Windows for setting up mex for compiling c++ code. There is a problem with setup for Cygwin which prevents me from using fopen. Hence, I installed mingw which solves the issue of fopen. But for a program which does not include fopen/fclose, I find that the performance is slower by the order of 5 in mingw when compared to cygwin. Is this behaviour expected?

Following are the gcc/g++ version used by cygwin and mingw:

D:\cygwin64\bin>gcc --version
gcc (GCC) 4.8.3
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

D:\mingw64\mingw64\bin>gcc --version
gcc (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Mingw is using a newer version of gcc. So, I would assume that it should be faster. But it is not the case.

Also, mex -v produces almost identical output when compiling the files: (the only differnce is in the LINKFLAGS. The order of -mwindows and GM_ISCPP is reversed.)

For Cygwin,

 This is mex, Copyright 1984-2007 The MathWorks, Inc. 

 -> Default options filename found in         C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b 
---------------------------------------------------------------- 
->    Options file           =     C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat 
  MATLAB                 = C:\PROGRA~1\MATLAB\R2009b 
->    COMPILER               = gcc 
->    Compiler flags: 
     COMPFLAGS           = -c -DMATLAB_MEX_FILE -x c++ 
     OPTIMFLAGS          = -O3 
     DEBUGFLAGS          = -g 
     arguments           =  
     Name switch         = -o 
->    Pre-linking commands   =  
->    LINKER                 =     C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl 
->    Link directives: 
     LINKFLAGS           =   -mwindows -    LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP   -mwindows 
     LINKDEBUGFLAGS      = -g  -Wl,--image-base,0x28000000\n 
     LINKFLAGSPOST       =  
     Name directive      = -o pnlFitness_cpp.mexw64 
     File link directive =  
     Lib. link directive =  
     Rsp file indicator  =  
 ->    Resource Compiler      =    C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\rccompile.pl -o mexversion.res 

 ->    Resource Linker        =  
---------------------------------------------------------------- 


 --> gcc  -c -DMATLAB_MEX_FILE -x c++ -   oC:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\pnlFitness_cpp.obj -    IC:\PROGRA~1\MATLAB\R2009b\extern\include -IC:\PROGRA~1\MATLAB\R2009b\simulink\include -O3 -DMX_COMPAT_32 pnlFitness_cpp.cpp 


--> C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl -o pnlFitness_cpp.mexw64   -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP   -mwindows -s  C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\pnlFitness_cpp.obj   

link command: g++ -shared C:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex\mex.def -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex  -mwindows -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\pnlFitness_cpp.obj -llibmx -llibmex -llibmat 

For Mingw,

This is mex, Copyright 1984-2007 The MathWorks, Inc. 

-> Default options filename found in C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b 
---------------------------------------------------------------- 
->    Options file           =   C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat 
      MATLAB                 = C:\PROGRA~1\MATLAB\R2009b 
->    COMPILER               = gcc 
->    Compiler flags: 
     COMPFLAGS           = -c -DMATLAB_MEX_FILE -x c++ 
     OPTIMFLAGS          = -O3 
     DEBUGFLAGS          = -g 
     arguments           =  
     Name switch         = -o 
->    Pre-linking commands   =  
->    LINKER                 = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl 
->    Link directives: 
     LINKFLAGS           = -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows GM_ISCPP 
     LINKDEBUGFLAGS      = -g  -Wl,--image-base,0x28000000\n 
     LINKFLAGSPOST       =  
     Name directive      = -o pnlFitness_cpp.mexw64 
     File link directive =  
     Lib. link directive =  
     Rsp file indicator  =  
->    Resource Compiler      = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\rccompile.pl  -o mexversion.res 
->    Resource Linker        =  
---------------------------------------------------------------- 


--> gcc  -c -DMATLAB_MEX_FILE -x c++ -oC:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_YK~1\pnlFitness_cpp.obj -IC:\PROGRA~1\MATLAB\R2009b\extern\include -IC:\PROGRA~1\MATLAB\R2009b\simulink\include -O3 -DMX_COMPAT_32 pnlFitness_cpp.cpp 


--> C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows GM_ISCPP -s  C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_YK~1\pnlFitness_cpp.obj   

link command: g++ -shared C:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex\mex.def -o pnlFitness_cpp.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex -mwindows  -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_YK~1\pnlFitness_cpp.obj -llibmx -llibmex -llibmat 
1
"There is a problem with setup for Cygwin which prevents me from using fopen" - then why not post a question about that?Mawg says reinstate Monica
I posted that question (stackoverflow.com/questions/28470459/…). No solution found, so I moved to minGw. Now the issue is performance in minGw.lonstud
"No solution found"? But you answered your own previous question now everything works fine". If that is not the case, please update the previous question, as it will be very misleading for anyone with the same problem.Mawg says reinstate Monica
I have made the appropriate changes in the previous question and deselected my answer. Also, made the necessary note that solution works with minGw but not with cygwin. Thank you for your suggestions.lonstud

1 Answers

0
votes

In my experience, MinGW normally generates code which runs faster than corresponding cygwin generated code ... sometimes significantly so. After all, MinGW generates native windows code, so it isn't encumbered by the overhead of cygwin's POSIX emulation layer.

Clearly, your experience differs from mine; I don't know why, and I don't know what overhead may be incurred via the Matlab infrastructure.