Commit 300cee50 authored by cbecker's avatar cbecker Committed by Guolin Ke
Browse files

Make openmp optional, allow for dylib mac library output (#204)

* Added possibility to compile without openmp (useful for clang on Mac)

* Added CMake option to create dylib on MacOS
parent 46818ac6
......@@ -3,6 +3,11 @@ cmake_minimum_required(VERSION 2.8)
PROJECT(lightgbm)
OPTION(USE_MPI "MPI based parallel learning" OFF)
OPTION(USE_OPENMP "Enable OpenMP" ON)
if(APPLE)
OPTION(APPLE_OUTPUT_DYLIB "Output dylib shared library" OFF)
endif()
if(USE_MPI)
find_package(MPI REQUIRED)
......@@ -13,9 +18,18 @@ else()
ADD_DEFINITIONS(-DUSE_SOCKET)
endif(USE_MPI)
find_package(OpenMP REQUIRED)
if(USE_OPENMP)
find_package(OpenMP REQUIRED)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
# Ignore unknown #pragma warning
if( (CMAKE_CXX_COMPILER_ID MATCHES "[cC][lL][aA][nN][gG]")
OR (CMAKE_CXX_COMPILER_ID MATCHES "[gG][nN][uU]"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
endif()
endif(USE_OPENMP)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
if(UNIX OR MINGW OR CYGWIN)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O3 -Wall -std=c++11")
......@@ -55,7 +69,11 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
include_directories (${LightGBM_HEADER_DIR})
if(APPLE)
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
if (APPLE_OUTPUT_DYLIB)
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
else()
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif()
endif(APPLE)
if(USE_MPI)
......
......@@ -4,7 +4,7 @@
#include <cstring>
#include <cstdio>
#include <sstream>
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <cstdint>
#include <memory>
......
#ifndef LIGHTGBM_OPENMP_WRAPPER_H_
#define LIGHTGBM_OPENMP_WRAPPER_H_
#ifdef _OPENMP
#include <omp.h>
#else
#ifdef _MSC_VER
#pragma warning( disable : 4068 ) // disable unknown pragma warning
#endif
#ifdef __cplusplus
extern "C" {
#endif
/** Fall here if no OPENMP support, so just
simulate a single thread running.
All #pragma omp should be ignored by the compiler **/
inline void omp_set_num_threads(int) {}
inline int omp_get_num_threads() {return 1;}
inline int omp_get_thread_num() {return 0;}
#ifdef __cplusplus
}; // extern "C"
#endif
#endif
#endif /* LIGHTGBM_OPENMP_WRAPPER_H_ */
#ifndef LIGHTGBM_UTILS_THREADING_H_
#define LIGHTGBM_UTILS_THREADING_H_
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <vector>
#include <functional>
......
......@@ -12,7 +12,7 @@
#include "predictor.hpp"
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <cstdio>
#include <ctime>
......
......@@ -6,7 +6,7 @@
#include <LightGBM/utils/text_reader.h>
#include <LightGBM/dataset.h>
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <cstring>
#include <cstdio>
......
#include "gbdt.h"
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/common.h>
......
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/common.h>
#include <LightGBM/utils/random.h>
......
......@@ -2,7 +2,7 @@
#include <LightGBM/feature.h>
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <cstdio>
#include <unordered_map>
......
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/log.h>
#include <LightGBM/dataset_loader.h>
......
......@@ -5,7 +5,7 @@
#include <LightGBM/bin.h>
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <cstring>
#include <cstdint>
......
......@@ -6,7 +6,7 @@
#include <LightGBM/metric.h>
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <sstream>
#include <vector>
......
......@@ -4,7 +4,7 @@
#include <LightGBM/meta.h>
#include <LightGBM/feature.h>
#include <omp.h>
#include <LightGBM/utils/openmp_wrapper.h>
#include <cstring>
......
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