Skip to content

Commit

Permalink
Making compile work better on Mac, make dependence on omp.h optional
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenbeckr committed Feb 26, 2019
1 parent 9403051 commit 9a794ad
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
51 changes: 46 additions & 5 deletions mexFiles/makeMex.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion mexFiles/prox_l1_and_sum_worker_mex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
#else
#define HAVE_AVX 0
#endif

#if defined(_OPENMP)
#include <omp.h>
#endif

#include <mex.h>

Expand Down
2 changes: 2 additions & 0 deletions mexFiles/shrink_mex2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#define HAVE_AVX 0
#endif

#if defined(_OPENMP)
#include <omp.h>
#endif

#include <mex.h>

Expand Down

0 comments on commit 9a794ad

Please sign in to comment.