Skip to content

Commit

Permalink
Add NUTS C++ example and update CMake (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
papachristoumarios authored Jun 4, 2022
1 parent 578b0b5 commit 0f1bb2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
41 changes: 26 additions & 15 deletions examples/logconcave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,25 @@ else ()
include_directories(BEFORE /usr/include/eigen3)
endif(BUILTIN_EIGEN)

if (USE_MKL)
find_library(BLAS NAME libblas.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
include_directories (BEFORE ${MKLROOT}/include)
set(PROJECT_LIBS ${BLAS_LIBRARIES})
add_definitions(-DEIGEN_USE_MKL_ALL)
endif(USE_MKL)
find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib)


if (USE_MKL)
find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib)
find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10)
find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib)
find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib)

include_directories (BEFORE ${MKLROOT}/include)
set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES})
set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl")
add_definitions(-DEIGEN_USE_MKL_ALL)
else()
set(MKL_LINK "")
endif(USE_MKL)

# Find lpsolve library
find_library(LP_SOLVE NAMES liblpsolve55.so PATHS /usr/lib/lp_solve)
find_library(LP_SOLVE NAMES liblpsolve55.so liblpsolve55.dylib PATHS /usr/lib/lp_solve /usr/local/lib)

if (NOT LP_SOLVE)
message(FATAL_ERROR "This program requires the lp_solve library, and will not be compiled.")
Expand Down Expand Up @@ -131,20 +141,21 @@ else ()
add_executable (simple_ode simple_ode.cpp)
add_executable (simple_uld simple_uld.cpp)
add_executable (simple_sde simple_sde.cpp)
add_executable (simple_nuts simple_nuts.cpp)
add_executable (high_dimensional_hmc high_dimensional_hmc.cpp)
add_executable (high_dimensional_hmc_rand_poly high_dimensional_hmc_rand_poly.cpp)
add_executable (exponential_exact_hmc exponential_exact_hmc.cpp)
add_executable (gaussian_exact_hmc gaussian_exact_hmc.cpp)

#add_executable (adaptive_step_size adaptive_step_size.cpp)

TARGET_LINK_LIBRARIES(high_dimensional_hmc_rand_poly ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
TARGET_LINK_LIBRARIES(high_dimensional_hmc ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
#TARGET_LINK_LIBRARIES(adaptive_step_size ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
TARGET_LINK_LIBRARIES(simple_ode ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
TARGET_LINK_LIBRARIES(simple_sde ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
TARGET_LINK_LIBRARIES(simple_uld ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
TARGET_LINK_LIBRARIES(simple_hmc ${LP_SOLVE} ${BLAS} "-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")

TARGET_LINK_LIBRARIES(high_dimensional_hmc_rand_poly ${LP_SOLVE} ${MKL_LINK})
TARGET_LINK_LIBRARIES(high_dimensional_hmc ${LP_SOLVE} ${MKL_LINK})
#TARGET_LINK_LIBRARIES(adaptive_step_size ${LP_SOLVE} ${MKL_LINK})
TARGET_LINK_LIBRARIES(simple_ode ${LP_SOLVE} ${MKL_LINK})
TARGET_LINK_LIBRARIES(simple_sde ${LP_SOLVE} ${MKL_LINK})
TARGET_LINK_LIBRARIES(simple_uld ${LP_SOLVE} ${MKL_LINK})
TARGET_LINK_LIBRARIES(simple_hmc ${LP_SOLVE} ${MKL_LINK})
TARGET_LINK_LIBRARIES(simple_nuts ${LP_SOLVE} ${MKL_LINK})

endif()
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ else ()
add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess)
add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke)
add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery)

add_executable (sampling_test sampling_test.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME test_dikin COMMAND sampling_test -tc=dikin)
add_test(NAME test_john COMMAND sampling_test -tc=john)
Expand All @@ -218,7 +218,7 @@ else ()
add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr)
add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw)
add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc)

add_executable (mmcs_test mmcs_test.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs)

Expand Down Expand Up @@ -302,7 +302,7 @@ else ()
COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated)
add_test(NAME logconcave_sampling_test_nuts_hmc
COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc)


add_executable (simple_mc_integration simple_mc_integration.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME simple_mc_integration_over_limits
Expand Down

0 comments on commit 0f1bb2f

Please sign in to comment.