From 9a794ad062b10839d80b4fef098f9db5a718668c Mon Sep 17 00:00:00 2001 From: Stephen Becker Date: Tue, 26 Feb 2019 09:58:37 -0700 Subject: [PATCH] Making compile work better on Mac, make dependence on omp.h optional --- mexFiles/makeMex.m | 51 +++++++++++++++++++++++--- mexFiles/prox_l1_and_sum_worker_mex.cc | 3 +- mexFiles/shrink_mex2.cc | 2 + 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/mexFiles/makeMex.m b/mexFiles/makeMex.m index 9ede88a..dff8839 100644 --- a/mexFiles/makeMex.m +++ b/mexFiles/makeMex.m @@ -49,11 +49,52 @@ function compileForMatlab( inputFile ) function compileForMatlabWithOptions( inputFile ) % Options are set a la mexopts.sh % See /usr/local/MATLAB/R2017a/bin/mexopts.sh - mex(inputFile,... - 'CFLAGS="$CFLAGS -O2 -march=native -mtune=native -fopenmp"',... - 'CLIBS="$CLIBS -lgomp"',... - 'CXXFLAGS="$CXXFLAGS -O2 -march=native -mtune=native -fopenmp"',... - 'CXXLIBS="$CXXLIBS -lgomp"') + try + % for MSVC-based compilers (e.g., Windows), + % try changing the + % CFLAGS="\$CFLAGS -fopenmp" + % to + % COMPFLAGS="/openmp" + myCCompiler = mex.getCompilerConfigurations('C','Selected'); + c_name = lower( myCCompiler.ShortName ); + if contains( c_name, {'gcc','clang'} ) + CC_type = 1; + elseif contains( c_name, 'msvcc' ) + CC_type = 2; + else + CC_type = 3; + end + switch CC_type + case 1 + mex(inputFile,... + 'CFLAGS="$CFLAGS -O2 -march=native -mtune=native -fopenmp"',... + 'CLIBS="$CLIBS -lgomp"',... + 'CXXFLAGS="$CXXFLAGS -O2 -march=native -mtune=native -fopenmp"',... + 'CXXLIBS="$CXXLIBS -lgomp"') + case 2 + % untested + mex(inputFile,... + 'COMPFLAGS="/openmp"' ); + case 3 + mex(inputFile ) + end + catch er + if strcmpi(er.identifier,'MATLAB:mex:Error') && ... + ~isempty( strfind( er.message, 'fopenmp' ) ) + disp('Warning, openMP not found on your system, code is not multi-threaded'); + if CC_type == 1 + mex(inputFile,... + 'CFLAGS="$CFLAGS -O2 -march=native -mtune=native"',... + 'CLIBS="$CLIBS -lgomp"',... + 'CXXFLAGS="$CXXFLAGS -O2 -march=native -mtune=native"',... + 'CXXLIBS="$CXXLIBS -lgomp"') + else + mex(inputFile ) + end + else + rethrow( er ); + end + end end function compileForOctave( inputFile ) diff --git a/mexFiles/prox_l1_and_sum_worker_mex.cc b/mexFiles/prox_l1_and_sum_worker_mex.cc index 6b40442..575ab1a 100644 --- a/mexFiles/prox_l1_and_sum_worker_mex.cc +++ b/mexFiles/prox_l1_and_sum_worker_mex.cc @@ -37,8 +37,9 @@ #else #define HAVE_AVX 0 #endif - +#if defined(_OPENMP) #include +#endif #include diff --git a/mexFiles/shrink_mex2.cc b/mexFiles/shrink_mex2.cc index e974c91..7681bd2 100644 --- a/mexFiles/shrink_mex2.cc +++ b/mexFiles/shrink_mex2.cc @@ -34,7 +34,9 @@ #define HAVE_AVX 0 #endif +#if defined(_OPENMP) #include +#endif #include