From: Hugo on
Hello,

I have installed gnumex v2.01 and MinGW v5.1.6 in Windows XP 32, in order to compile files in Matlab that have been paralellized with OpenMP since it supports the compiler gcc.

I can "mex" C files now using gcc in Windows without any problem, but I wonder what do I have to do in order to mex files that use OpenMP (omp.h), do I have to edit the "mexopts.bat" file generated by "gnumex"? what lines do I have to add?

I'm using Windows XP 32, Matlab 7.5 R2007b

Thank you very much!
From: Oliver Woodford on
"Hugo" wrote:
> Hello,
>
> I have installed gnumex v2.01 and MinGW v5.1.6 in Windows XP 32, in order to compile files in Matlab that have been paralellized with OpenMP since it supports the compiler gcc.
>
> I can "mex" C files now using gcc in Windows without any problem, but I wonder what do I have to do in order to mex files that use OpenMP (omp.h), do I have to edit the "mexopts.bat" file generated by "gnumex"? what lines do I have to add?
>
> I'm using Windows XP 32, Matlab 7.5 R2007b
>
> Thank you very much!

You can edit mexopts.bat or pass the relevant flag in to mex on the command line. Either way, the flag the compiler needs is -fopenmp.

This recent thread explains how to do the latter:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/286669
From: Hugo on
Thank you very much for the answer, but in order to edit mexopts.bat instead of passing flags, do you know which lines should I edit to use OpenMP?

The mexopts.bat generated by gnumex is:

@echo off
rem C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2007b\mexopts.bat
rem Generated by gnumex.m script in c:\gnumex
rem gnumex version: 2.01
rem Compile and link options used for building MEX etc files with
rem the Mingw/Cygwin tools. Options here are:
rem Gnumex, version 2.01
rem MinGW linking
rem Mex (*.dll) creation
rem Libraries regenerated now
rem Language: C / C++
rem Optimization level: -O3 (full optimization)
rem Matlab version 7.5
rem
set MATLAB=C:\PROGRA~1\MATLAB\R2007b
set GM_PERLPATH=C:\PROGRA~1\MATLAB\R2007b\sys\perl\win32\bin\perl.exe
set GM_UTIL_PATH=c:\gnumex
set PATH=c:\mingw\bin;%PATH%
set PATH=%PATH%;C:\Cygwin\usr\local\gfortran\libexec\gcc\i686-pc-cygwin\4.3.0
set LIBRARY_PATH=c:\mingw\lib
set G95_LIBRARY_PATH=c:\mingw\lib
rem
rem precompiled library directory and library files
set GM_QLIB_NAME=C:\DOCUME~1\ADMINI~1\APPLIC~1\MATHWO~1\MATLAB\R2007b\gnumex
rem
rem directory for .def-files
set GM_DEF_PATH=C:\DOCUME~1\ADMINI~1\APPLIC~1\MATHWO~1\MATLAB\R2007b\gnumex
rem
rem Type of file to compile (mex or engine)
set GM_MEXTYPE=mex
rem
rem Language for compilation
set GM_MEXLANG=c
rem
rem File for exporting mexFunction symbol
set GM_MEXDEF=C:\DOCUME~1\ADMINI~1\APPLIC~1\MATHWO~1\MATLAB\R2007b\gnumex\mex.def
rem
set GM_ADD_LIBS=-llibmx -llibmex -llibmat
rem
rem compiler options; add compiler flags to compflags as desired
set NAME_OBJECT=-o
set COMPILER=gcc
set COMPFLAGS=-c -DMATLAB_MEX_FILE
set OPTIMFLAGS=-O3
set DEBUGFLAGS=-g
set CPPCOMPFLAGS=%COMPFLAGS% -x c++
set CPPOPTIMFLAGS=%OPTIMFLAGS%
set CPPDEBUGFLAGS=%DEBUGFLAGS%
rem
rem NB Library creation commands occur in linker scripts
rem
rem Linker parameters
set LINKER=%GM_PERLPATH% %GM_UTIL_PATH%\linkmex.pl
set LINKFLAGS=
set CPPLINKFLAGS=GM_ISCPP
set LINKOPTIMFLAGS=-s
set LINKDEBUGFLAGS=-g -Wl,--image-base,0x28000000\n
set LINKFLAGS= -LC:\DOCUME~1\ADMINI~1\APPLIC~1\MATHWO~1\MATLAB\R2007b\gnumex
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o %OUTDIR%%MEX_NAME%.mexw32
rem
rem Resource compiler parameters
set RC_COMPILER=%GM_PERLPATH% %GM_UTIL_PATH%\rccompile.pl -o %OUTDIR%mexversion.res
set RC_LINKER=

Thank you very much!!!
From: Oliver Woodford on
Try changing:
set COMPFLAGS=-c -DMATLAB_MEX_FILE
to:
set COMPFLAGS=-c -DMATLAB_MEX_FILE -fopenmp
From: Hugo on
Hello, thank you for your suggestion but it is not working, I changed the line in the mexopts.bat and I received this in Matlab command:

>> mex -f mexopts.bat test.c
cc1.exe: error: unrecognized command line option "-fopenmp"