mex: support compilation on mac with clang + openmp

parent 53ae5493
Pipeline #1557 passed with stages
in 102 minutes and 39 seconds
......@@ -70,6 +70,11 @@ dynareroot = dynare_config('', preprocessoroutput);
warning_config()
% For OpenMP on Mac
if ismac
setenv('KMP_DUPLICATE_LIB_OK', 'TRUE');
end
if isoctave
% The supported_octave_version.m file is not in git nor in the source
% package, it is manually added in binary packages distributed on dynare.org
......
......@@ -3,7 +3,13 @@ mex_PROGRAMS = block_kalman_filter
TOPDIR = $(top_srcdir)/../../sources/block_kalman_filter
block_kalman_filter_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR)
if MACOS
block_kalman_filter_CXXFLAGS = $(AM_CXXFLAGS) -Xpreprocessor -fopenmp
block_kalman_filter_LDADD = -lomp
else
block_kalman_filter_CXXFLAGS = $(AM_CXXFLAGS) -fopenmp
endif
nodist_block_kalman_filter_SOURCES = block_kalman_filter.cc
......
......@@ -3,7 +3,12 @@ mex_PROGRAMS = sparse_hessian_times_B_kronecker_C A_times_B_kronecker_C
nodist_sparse_hessian_times_B_kronecker_C_SOURCES = sparse_hessian_times_B_kronecker_C.cc
nodist_A_times_B_kronecker_C_SOURCES = A_times_B_kronecker_C.cc
if MACOS
sparse_hessian_times_B_kronecker_C_CXXFLAGS = $(AM_CXXFLAGS) -Xpreprocessor -fopenmp
sparse_hessian_times_B_kronecker_C_LDADD = -lomp
else
sparse_hessian_times_B_kronecker_C_CXXFLAGS = $(AM_CXXFLAGS) -fopenmp
endif
BUILT_SOURCES = $(nodist_sparse_hessian_times_B_kronecker_C_SOURCES) $(nodist_A_times_B_kronecker_C_SOURCES)
CLEANFILES = $(nodist_sparse_hessian_times_B_kronecker_C_SOURCES) $(nodist_A_times_B_kronecker_C_SOURCES)
......
......@@ -2,7 +2,12 @@ mex_PROGRAMS = local_state_space_iteration_2
nodist_local_state_space_iteration_2_SOURCES = local_state_space_iteration_2.cc
if MACOS
local_state_space_iteration_2_CXXFLAGS = $(AM_CXXFLAGS) -Xpreprocessor -fopenmp
local_state_space_iteration_2_LDADD = -lomp
else
local_state_space_iteration_2_CXXFLAGS = $(AM_CXXFLAGS) -fopenmp
endif
BUILT_SOURCES = $(nodist_local_state_space_iteration_2_SOURCES)
CLEANFILES = $(nodist_local_state_space_iteration_2_SOURCES)
......
......@@ -64,8 +64,10 @@ AX_PROG_LN_S
AC_PROG_MKDIR_P
AM_PROG_AR
build_mac=no
case ${host_os} in
*darwin*)
build_mac=yes
string=$($CXX --version)
if test "${string#*clang}" != "$string"; then
CXXFLAGS="$CXXFLAGS -stdlib=libc++"
......@@ -79,6 +81,8 @@ esac
AX_CXX11_THREAD
AM_CONDITIONAL([MACOS], [test "$build_mac" = "yes"])
# Check for dlopen(), needed by k_order_perturbation DLL
AC_CHECK_LIB([dl], [dlopen], [LIBADD_DLOPEN="-ldl"], [])
AC_SUBST([LIBADD_DLOPEN])
......
......@@ -70,13 +70,17 @@ AM_CONDITIONAL([HAVE_SLICOT], [test "$has_slicot" = yes])
AC_CHECK_LIB([umfpack], [umfpack_dl_defaults], [LIBADD_UMFPACK="-lumfpack"], [AC_MSG_ERROR([Can't find UMFPACK])])
# For OS X, explicitly add libraries that libumfpack depends on as Homebrew
# doesn't support the creation of shared libraries for suite-sparse 3.7.0
build_mac=no
case ${host_os} in
darwin*)
build_mac=yes
LIBADD_UMFPACK="-lumfpack -lcholmod -lcolamd -lamd"
;;
esac
AC_SUBST([LIBADD_UMFPACK])
AM_CONDITIONAL([MACOS], [test "$build_mac" = "yes"])
AM_CONDITIONAL([DO_SOMETHING], [test -n "$MKOCTFILE"])
if test -n "$MKOCTFILE"; then
......
......@@ -5,8 +5,13 @@ TOPDIR = $(top_srcdir)/../../sources/perfect_foresight_problem
nodist_perfect_foresight_problem_SOURCES = perfect_foresight_problem.cc DynamicModelCaller.cc
perfect_foresight_problem_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR)
if MACOS
perfect_foresight_problem_CXXFLAGS = $(AM_CXXFLAGS) -Xpreprocessor -fopenmp
perfect_foresight_problem_LDADD = $(LIBADD_DLOPEN) -lomp
else
perfect_foresight_problem_CXXFLAGS = $(AM_CXXFLAGS) -fopenmp
perfect_foresight_problem_LDADD = $(LIBADD_DLOPEN)
endif
BUILT_SOURCES = $(nodist_perfect_foresight_problem_SOURCES)
CLEANFILES = $(nodist_perfect_foresight_problem_SOURCES)
......
......@@ -3,7 +3,12 @@ mex_PROGRAMS = qmc_sequence
TOPDIR = $(top_srcdir)/../../sources/sobol
qmc_sequence_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR)
if MACOS
qmc_sequence_CXXFLAGS = $(AM_CXXFLAGS) -Xpreprocessor -fopenmp
qmc_sequence_LDADD = -lomp
else
qmc_sequence_CXXFLAGS = $(AM_CXXFLAGS) -fopenmp
endif
nodist_qmc_sequence_SOURCES = qmc_sequence.cc
......
  • Does this work? Do you want to have this merged?

    If the answer to both questions is yes, then I would suggest rewriting this patch by introducing two variables (something like OPENMP_CXXFLAGS and OPENMP_LDADD) that would be set by the configure script and that would contain whatever is relevant for the platform (i.e. respectively -fopenmp and nothing on GNU/Linux and Windows, and whatever is needed on macOS). Hence the check for the MACOS conditional in all *.am files could be removed.

  • I just pushed that in case it would be useful in the future. It compiles and runs but I don't like the solution setting KMP_DUPLICATE_LIB_OK to true. So, for now, we should just keep this in a branch.

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment