diff --git a/.gitignore b/.gitignore index b0d664866..27ff1a764 100644 --- a/.gitignore +++ b/.gitignore @@ -52,8 +52,6 @@ Debug #.Rbuildignore R-package.Rproj *.cache* -R-package/inst -R-package/src #java java/xgboost4j/target java/xgboost4j/tmp diff --git a/Makefile b/Makefile index d33b0e172..a9ed1f96f 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,12 @@ ifndef RABIT endif ROOTDIR = $(CURDIR) -UNAME= $(shell uname) + +ifeq ($(OS), Windows_NT) + UNAME="Windows" +else + UNAME=$(shell uname) +endif include $(config) ifeq ($(USE_OPENMP), 0) @@ -34,13 +39,8 @@ ifndef CXX export CXX = $(if $(shell which g++-5),g++-5,g++) endif -ifeq ($(OS), Windows_NT) - export CXX = g++ -m64 - export CC = gcc -m64 -endif - export LDFLAGS= -pthread -lm $(ADD_LDFLAGS) $(DMLC_LDFLAGS) $(PLUGIN_LDFLAGS) -export CFLAGS= -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fPIC -Iinclude $(ADD_CFLAGS) $(PLUGIN_CFLAGS) +export CFLAGS= -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude $(ADD_CFLAGS) $(PLUGIN_CFLAGS) CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include #java include path export JAVAINCFLAGS = -I${JAVA_HOME}/include -I./java @@ -49,6 +49,13 @@ ifndef LINT_LANG LINT_LANG= "all" endif +ifneq ($(UNAME), Windows) + CFLAGS += -fPIC + XGBOOST_DYLIB = lib/libxgboost.so +else + XGBOOST_DYLIB = lib/libxgboost.dll +endif + ifeq ($(UNAME), Linux) LDFLAGS += -lrt JAVAINCFLAGS += -I${JAVA_HOME}/include/linux @@ -68,7 +75,8 @@ endif # specify tensor path .PHONY: clean all lint clean_all doxygen rcpplint Rpack Rbuild Rcheck java -all: lib/libxgboost.a lib/libxgboost.so xgboost + +all: lib/libxgboost.a $(XGBOOST_DYLIB) xgboost $(DMLC_CORE)/libdmlc.a: + cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR) @@ -108,7 +116,7 @@ lib/libxgboost.a: $(ALL_DEP) @mkdir -p $(@D) ar crv $@ $(filter %.o, $?) -lib/libxgboost.so: $(ALL_DEP) +lib/libxgboost.dll lib/libxgboost.so: $(ALL_DEP) @mkdir -p $(@D) $(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS) @@ -125,11 +133,11 @@ lint: rcpplint python2 dmlc-core/scripts/lint.py xgboost ${LINT_LANG} include src plugin clean: - $(RM) -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ amalgamation/*.o xgboost + $(RM) -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o xgboost clean_all: clean - cd $(DMLC_CORE); make clean; cd - - cd $(RABIT); make clean; cd - + cd $(DMLC_CORE); make clean; cd $(ROODIR) + cd $(RABIT); make clean; cd $(ROODIR) doxygen: doxygen doc/Doxyfile diff --git a/R-package/README.md b/R-package/README.md index c92bc9b96..da176896a 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -16,7 +16,7 @@ install.packages('xgboost') For up-to-date version, please install from github. Windows user will need to install [RTools](http://cran.r-project.org/bin/windows/Rtools/) first. ```r -devtools::install_github('dmlc/xgboost',subdir='R-package') +devtools::install_git('git://github.com/dmlc/xgboost',subdir='R-package') ``` Examples diff --git a/R-package/src/Makevars b/R-package/src/Makevars index 0b7d3f084..14472acc8 100644 --- a/R-package/src/Makevars +++ b/R-package/src/Makevars @@ -2,9 +2,16 @@ PKGROOT=../../ ENABLE_STD_THREAD=1 # _*_ mode: Makefile; _*_ + CXX_STD = CXX11 -XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include $(XGB_RFLAGS) + +XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\ + -DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\ + -DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_CUSTOMIZE_LOGGER=1\ + -DRABIT_CUSTOMIZE_MSG_ -DRABIT_STRICT_CXX98_ + +PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include -I$(PKGROOT) $(XGB_RFLAGS) PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -OBJECTS= ./xgboost_R.o $(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o +OBJECTS= ./xgboost_R.o ./xgboost_custom.o ./xgboost_assert.o\ + $(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o diff --git a/R-package/src/Makevars.win b/R-package/src/Makevars.win index 20ad085ba..4134487fa 100644 --- a/R-package/src/Makevars.win +++ b/R-package/src/Makevars.win @@ -16,10 +16,16 @@ xgblib: cp -r ../../amalgamation . CXX_STD = CXX11 -XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include $(XGB_RFLAGS) + +XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\ + -DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\ + -DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_CUSTOMIZE_LOGGER=1\ + -DRABIT_CUSTOMIZE_MSG_ -DRABIT_STRICT_CXX98_ + +PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include -I$(PKGROOT) $(XGB_RFLAGS) PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -OBJECTS= ./xgboost_R.o $(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o +OBJECTS= ./xgboost_R.o ./xgboost_custom.o ./xgboost_assert.o\ + $(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o $(OBJECTS) : xgblib diff --git a/R-package/src/xgboost_R.cc b/R-package/src/xgboost_R.cc index e2ad6926f..665fb5faa 100644 --- a/R-package/src/xgboost_R.cc +++ b/R-package/src/xgboost_R.cc @@ -34,16 +34,6 @@ error(XGBGetLastError()); \ } -namespace xgboost { -namespace common { -bool CheckNAN(double v) { - return ISNAN(v); -} -double LogGamma(double v) { - return lgammafn(v); -} -} // namespace common -} // namespace xgboost using namespace dmlc; diff --git a/R-package/src/xgboost_assert.c b/R-package/src/xgboost_assert.c new file mode 100644 index 000000000..4706a039e --- /dev/null +++ b/R-package/src/xgboost_assert.c @@ -0,0 +1,26 @@ +// Copyright (c) 2014 by Contributors +#include +#include +#include + +// implements error handling +void XGBoostAssert_R(int exp, const char *fmt, ...) { + char buf[1024]; + if (exp == 0) { + va_list args; + va_start(args, fmt); + vsprintf(buf, fmt, args); + va_end(args); + error("AssertError:%s\n", buf); + } +} +void XGBoostCheck_R(int exp, const char *fmt, ...) { + char buf[1024]; + if (exp == 0) { + va_list args; + va_start(args, fmt); + vsprintf(buf, fmt, args); + va_end(args); + error("%s\n", buf); + } +} diff --git a/R-package/src/xgboost_custom.cc b/R-package/src/xgboost_custom.cc new file mode 100644 index 000000000..9d0de76c4 --- /dev/null +++ b/R-package/src/xgboost_custom.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2015 by Contributors +// This file contains the customization implementations of R module +// to change behavior of libxgboost + +#include +#include "src/common/random.h" +#include "./xgboost_R.h" + +// redirect the messages to R's console. +namespace dmlc { +void CustomLogMessage::Log(const std::string& msg) { + Rprintf("%s\n", msg.c_str()); +} +} // namespace dmlc + +// implements rabit error handling. +extern "C" { + void XGBoostAssert_R(int exp, const char *fmt, ...); + void XGBoostCheck_R(int exp, const char *fmt, ...); +} + +namespace rabit { +namespace utils { +extern "C" { + void (*Printf)(const char *fmt, ...) = Rprintf; + void (*Assert)(int exp, const char *fmt, ...) = XGBoostAssert_R; + void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R; + void (*Error)(const char *fmt, ...) = error; +} +} +} + +namespace xgboost { +ConsoleLogger::~ConsoleLogger() { + dmlc::CustomLogMessage::Log(log_stream_.str()); +} +TrackerLogger::~TrackerLogger() { + dmlc::CustomLogMessage::Log(log_stream_.str()); +} +} // namespace xgboost + +namespace xgboost { +namespace common { + +// redirect the nath functions. +bool CheckNAN(double v) { + return ISNAN(v); +} +double LogGamma(double v) { + return lgammafn(v); +} + +// customize random engine. +void CustomGlobalRandomEngine::seed(CustomGlobalRandomEngine::result_type val) { + // ignore the seed +} + +// use R's PRNG to replacd +CustomGlobalRandomEngine::result_type +CustomGlobalRandomEngine::operator()() { + return static_cast( + std::floor(unif_rand() * CustomGlobalRandomEngine::max())); +} +} // namespace common +} // namespace xgboost diff --git a/dmlc-core b/dmlc-core index 42428bc7e..ad2ddde8b 160000 --- a/dmlc-core +++ b/dmlc-core @@ -1 +1 @@ -Subproject commit 42428bc7e79fb3ff80322ca8bc2fdd8026cbc04d +Subproject commit ad2ddde8b6624abf3007a71b2923c3925530cc81 diff --git a/doc/build.md b/doc/build.md index 7eae0bbd0..82ff00a27 100644 --- a/doc/build.md +++ b/doc/build.md @@ -1,28 +1,145 @@ -Build XGBoost -============= -* Run ```bash build.sh``` (you can also type make) -* If you have C++11 compiler, it is recommended to type ```make cxx11=1``` - - C++11 is not used by default -* If your compiler does not come with OpenMP support, it will fire an warning telling you that the code will compile into single thread mode, and you will get single thread xgboost -* You may get a error: -lgomp is not found - - You can type ```make no_omp=1```, this will get you single thread xgboost - - Alternatively, you can upgrade your compiler to compile multi-thread version -* Windows(VS 2010): see [../windows](../windows) folder - - In principle, you put all the cpp files in the Makefile to the project, and build -* OS X with multi-threading support: see [next section](#openmp-for-os-x) +Installation Guide +================== -Build XGBoost in OS X with OpenMP ---------------------------------- -Here is the complete solution to use OpenMp-enabled compilers to install XGBoost. +This page gives instructions of how to build and install the xgboost package from +scratch on various systems. It consists of two steps: -1. Obtain gcc-5.x.x with openmp support by `brew install gcc --without-multilib`. (`brew` is the de facto standard of `apt-get` on OS X. So installing [HPC](http://hpc.sourceforge.net/) separately is not recommended, but it should work.) +1. Fist build the shared library from the C++ codes (`libxgboost.so` for linux/osx and `libxgboost.dll` for windows). + - Exception: for R-package installation please directly refer to the R package section. +2. Then install the language packages (e.g. Python Package). -2. `cd xgboost` then `bash build.sh` to compile XGBoost. +Please refer to [Installation FAQ](#frequently-asked-questions) first if you had any problem +during installation. If the instructions do not work for you, please feel free +to ask questions at [xgboost/issues](https://github.com/dmlc/xgboost/issues), or +even better to send pull request if you can fix the problem. -3. Install xgboost package for Python and R +## Contents +- [Build the Shared Library](#build-the-shared-library) + - [Prerequisites](#prerequisites) + - [Building on Ubuntu/Debian](#building-on-ubuntu-debian) + - [Building on OSX](#building-on-osx) + - [Building on Windows](#building-on-windows) + - [Customized Building](#customized-building) +- [Python Package Installation](#python-package-installation) +- [R Package Installation](#r-package-installation) +- [Docker Images](#docker-images) +- [Frequently asked questions](#frequently-asked-questions) -- For Python: go to `python-package` sub-folder to install python version with `python setup.py install` (or `sudo python setup.py install`). -- For R: Set the `Makevars` file in highest piority for R. +## Build the Shared Library + +Our goal is to build the shared library: +- On Linux/OSX the target library is ```libxgboost.so``` +- On Windows the target libary is ```libxgboost.dll``` + +The minimal building requirement is + +- A recent c++ compiler supporting C++ 11 (g++-4.6 or higher) + +We can edit `make/config.mk` to change the compile options, and then build by +`make`. If everything goes well, we can go the specific language installation section. + +### Building on Ubuntu/Debian + +On Ubuntu, one build xgboost by + +Then build xgboost +```bash +git clone --recursive https://github.com/dmlc/xgboost +cd xgboost; make -j4 +``` + +### Building on OSX + +On Ubuntu OSX, one build xgboost by + +```bash +git clone --recursive https://github.com/dmlc/xgboost +cd xgboost; cp make/minimum.mk ./config.mk; make -j4 +``` + +This build xgboost without multi-threading, because by default clang in OSX does not come with open-mp. +See the following paragraph for OpenMP enabled xgboost. + + +Here is the complete solution to use OpenMP-enabled compilers to install XGBoost. +Obtain gcc-5.x.x with openmp support by `brew install gcc --without-multilib`. (`brew` is the de facto standard of `apt-get` on OS X. So installing [HPC](http://hpc.sourceforge.net/) separately is not recommended, but it should work.) + +```bash +git clone --recursive https://github.com/dmlc/xgboost +cd xgboost; cp make/config.mk ./config.mk; make -j4 +``` + +### Building on Windows + +XGBoost support both build by MSVC or MinGW. Here is how you can build xgboost library using MinGW. + +Build with mingw +```bash +cp make/mingw64.mk config.mk; make -j4 +``` + +The MSVC build for new version is not yet updated. + + +### Customized Building + +The configuration of xgboost can be modified by ```config.mk``` +- modify configuration on various distributed filesystem such as HDFS/Amazon S3/... +- First copy [make/config.mk](../make/config.mk) to the project root, on which + any local modification will be ignored by git, then modify the according flags. + + + +## Python Package Installation + +The python package is located at [python-package](../python-package). +There are several ways to install the package: + +1. Install system-widely, which requires root permission + + ```bash + cd python; sudo python setup.py install + ``` + + You will however need Python `distutils` module for this to + work. It is often part of the core python package or it can be installed using your + package manager, e.g. in Debian use + + ```bash + sudo apt-get install python-setuptools + ``` + + *NOTE: If you recompiled xgboost, then you need to reinstall it again to + make the new library take effect* + +2. Only set the environment variable `PYTHONPATH` to tell python where to find + the library. For example, assume we cloned `xgboost` on the home directory + `~`. then we can added the following line in `~/.bashrc` + It is ***recommended for developers*** who may change the codes. The changes will be immediately reflected once you pulled the code and rebuild the project (no need to call ```setup``` again) + + ```bash + export PYTHONPATH=~/xgboost/python-package + ``` + +3. Install only for the current user. + + ```bash + cd python; python setup.py develop --user + ``` + +## R Package Installation + +You can install R package using devtools + +```r +devtools::install_git('git://github.com/dmlc/xgboost',subdir='R-package') + +``` + +For OSX users, single threaded version will be installed, to install multi-threaded version. +First follow [Building on OSX](#building-on-osx) to get the OpenMP enabled compiler, then: + +- Set the `Makevars` file in highest piority for R. The point is, there are three `Makevars` : `~/.R/Makevars`, `xgboost/R-package/src/Makevars`, and `/usr/local/Cellar/r/3.2.0/R.framework/Resources/etc/Makeconf` (the last one obtained by running `file.path(R.home("etc"), "Makeconf")` in R), and `SHLIB_OPENMP_CXXFLAGS` is not set by default!! After trying, it seems that the first one has highest piority (surprise!). @@ -38,13 +155,19 @@ Here is the complete solution to use OpenMp-enabled compilers to install XGBoost devtools::install_local('xgboost/', subdir = 'R-package') # you may use devtools ``` +## Frequent Asked Questions -Build with HDFS and S3 Support ------------------------------- -* To build xgboost use with HDFS/S3 support and distributed learnig. It is recommended to build with dmlc, with the following steps - - ```git clone https://github.com/dmlc/dmlc-core``` - - Follow instruction in dmlc-core/make/config.mk to compile libdmlc.a - - In root folder of xgboost, type ```make dmlc=dmlc-core``` -* This will allow xgboost to directly load data and save model from/to hdfs and s3 - - Simply replace the filename with prefix s3:// or hdfs:// -* This xgboost that can be used for distributed learning +1. **Compile failed after `git pull`** + + Please first update the submodules, clean all and recompile: + + ```bash + git submodule update && make clean_all && make -j4 + ``` + +2. **Compile failed after `config.mk` is modified** + Need to clean all first: + + ```bash + make clean_all && make -j4 + ``` diff --git a/include/xgboost/base.h b/include/xgboost/base.h index 64892e67c..3674c6117 100644 --- a/include/xgboost/base.h +++ b/include/xgboost/base.h @@ -25,6 +25,20 @@ #define XGBOOST_LOG_WITH_TIME 1 #endif +/*! + * \brief Whether customize the logger outputs. + */ +#ifndef XGBOOST_CUSTOMIZE_LOGGER +#define XGBOOST_CUSTOMIZE_LOGGER XGBOOST_STRICT_R_MODE +#endif + +/*! + * \brief Whether to customize global PRNG. + */ +#ifndef XGBOOST_CUSTOMIZE_GLOBAL_PRNG +#define XGBOOST_CUSTOMIZE_GLOBAL_PRNG XGBOOST_STRICT_R_MODE +#endif + /*! \brief namespace of xgboo st*/ namespace xgboost { /*! diff --git a/make/mingw64.mk b/make/mingw64.mk new file mode 100644 index 000000000..e20220bfc --- /dev/null +++ b/make/mingw64.mk @@ -0,0 +1,30 @@ +#----------------------------------------------------------- +# xgboost: Configuration for MinGW(Windows 64bit) +# This allows to compile xgboost on windows by using mingw. +# You will need to get install an mingw toolchain. +# g++-4.6 or later is required. +# +# see config.mk for template. +#----------------------------------------------------------- +export CXX=g++ -m64 +export CC=gcc -m64 + +# Whether enable openmp support, needed for multi-threading. +USE_OPENMP = 1 + +# whether use HDFS support during compile +USE_HDFS = 0 + +# whether use AWS S3 support during compile +USE_S3 = 0 + +# whether use Azure blob support during compile +USE_AZURE = 0 + +# Rabit library version, +# - librabit.a Normal distributed version. +# - librabit_empty.a Non distributed mock version, +LIB_RABIT = librabit_empty.a + +DMLC_CFLAGS = -DDMLC_ENABLE_STD_THREAD=0 +ADD_CFLAGS = -DDMLC_ENABLE_STD_THREAD=0 \ No newline at end of file diff --git a/python-package/MANIFEST.in b/python-package/MANIFEST.in index 83596d826..04ca379a6 100644 --- a/python-package/MANIFEST.in +++ b/python-package/MANIFEST.in @@ -1,14 +1,11 @@ -include *.sh *.md *.rst +include *.md *.rst recursive-include xgboost * -recursive-include xgboost/wrapper * -recursive-include xgboost/windows * -recursive-include xgboost/subtree * +recursive-include xgboost/include * recursive-include xgboost/src * -recursive-include xgboost/multi-node * #exclude pre-compiled .o file for less confusions #include the pre-compiled .so is needed as a placeholder #since it will be copy after compiling on the fly -global-exclude xgboost/wrapper/*.so.gz +global-exclude xgboost/build/* global-exclude xgboost/*.o global-exclude *.pyo global-exclude *.pyc diff --git a/python-package/setup.py b/python-package/setup.py index 4b05bc710..155a30bc8 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -17,7 +17,7 @@ libpath = {'__file__': libpath_py} exec(compile(open(libpath_py, "rb").read(), libpath_py, 'exec'), libpath, libpath) LIB_PATH = libpath['find_lib_path']() - +print("Install libxgboost from: %s" % LIB_PATH) #Please use setup_pip.py for generating and deploying pip installation #detailed instruction in setup_pip.py setup(name='xgboost', diff --git a/src/common/common.cc b/src/common/common.cc index 398f12186..6e12045f6 100644 --- a/src/common/common.cc +++ b/src/common/common.cc @@ -7,8 +7,8 @@ namespace xgboost { namespace common { -RandomEngine& GlobalRandom() { - static RandomEngine inst; +GlobalRandomEngine& GlobalRandom() { + static GlobalRandomEngine inst; return inst; } } diff --git a/src/common/math.h b/src/common/math.h index 479cc17d8..518da23bb 100644 --- a/src/common/math.h +++ b/src/common/math.h @@ -113,7 +113,7 @@ inline bool CheckNAN(T v) { #ifdef _MSC_VER return (_isnan(v) != 0); #else - return isnan(v); + return std::isnan(v); #endif } template diff --git a/src/common/random.h b/src/common/random.h index fe9bfe3a7..f47ff5f75 100644 --- a/src/common/random.h +++ b/src/common/random.h @@ -8,6 +8,7 @@ #define XGBOOST_COMMON_RANDOM_H_ #include +#include namespace xgboost { namespace common { @@ -15,11 +16,54 @@ namespace common { * \brief Define mt19937 as default type Random Engine. */ typedef std::mt19937 RandomEngine; + +#if XGBOOST_CUSTOMIZE_GLOBAL_PRNG +/*! + * \brief An customized random engine, used to be plugged in PRNG from other systems. + * The implementation of this library is not provided by xgboost core library. + * Instead the other library can implement this class, which will be used as GlobalRandomEngine + * If XGBOOST_RANDOM_CUSTOMIZE = 1, by default this is switched off. + */ +class CustomGlobalRandomEngine { + public: + /*! \brief The result type */ + typedef size_t result_type; + /*! \brief The minimum of random numbers generated */ + inline static constexpr result_type min() { + return 0; + } + /*! \brief The maximum random numbers generated */ + inline static constexpr result_type max() { + return std::numeric_limits::max(); + } + /*! + * \brief seed function, to be implemented + * \param val The value of the seed. + */ + void seed(result_type val); + /*! + * \return next random number. + */ + result_type operator()(); +}; + +/*! + * \brief global random engine + */ +typedef CustomGlobalRandomEngine GlobalRandomEngine; + +#else +/*! + * \brief global random engine + */ +typedef RandomEngine GlobalRandomEngine; +#endif + /*! * \brief global singleton of a random engine. * Only use this engine when necessary, not thread-safe. */ -RandomEngine& GlobalRandom(); // NOLINT(*) +GlobalRandomEngine& GlobalRandom(); // NOLINT(*) } // namespace common } // namespace xgboost diff --git a/src/data/sparse_page_dmatrix.cc b/src/data/sparse_page_dmatrix.cc index 4fe139910..0cbf27e5d 100644 --- a/src/data/sparse_page_dmatrix.cc +++ b/src/data/sparse_page_dmatrix.cc @@ -8,6 +8,8 @@ #include #include #include + +#if DMLC_ENABLE_STD_THREAD #include "./sparse_page_dmatrix.h" #include "../common/random.h" #include "../common/group_data.h" @@ -278,3 +280,4 @@ void SparsePageDMatrix::InitColAccess(const std::vector& enabled, } // namespace data } // namespace xgboost +#endif diff --git a/src/data/sparse_page_source.cc b/src/data/sparse_page_source.cc index 593a8d9b8..5730da9b5 100644 --- a/src/data/sparse_page_source.cc +++ b/src/data/sparse_page_source.cc @@ -6,6 +6,8 @@ #include #include #include + +#if DMLC_ENABLE_STD_THREAD #include "./sparse_page_source.h" namespace xgboost { @@ -175,3 +177,4 @@ void SparsePageSource::Create(DMatrix* src, } // namespace data } // namespace xgboost +#endif diff --git a/src/learner.cc b/src/learner.cc index 9a7ebda22..f787be9fc 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -334,7 +334,8 @@ class LearnerImpl : public Learner { // in distributed mode, use safe choice otherwise size_t max_row_perbatch = tparam.max_row_perbatch; if (tparam.test_flag == "block" || tparam.dsplit == 2) { - max_row_perbatch = std::min(32UL << 10UL, max_row_perbatch); + max_row_perbatch = std::min( + static_cast(32UL << 10UL), max_row_perbatch); } // initialize column access p_train->InitColAccess(enabled, diff --git a/src/logging.cc b/src/logging.cc index ffb249bd2..f579f9a97 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -9,6 +9,8 @@ #include "./common/sync.h" namespace xgboost { + +#if XGBOOST_CUSTOMIZE_LOGGER == 0 ConsoleLogger::~ConsoleLogger() { std::cout << log_stream_.str() << std::endl; } @@ -17,4 +19,5 @@ TrackerLogger::~TrackerLogger() { log_stream_ << '\n'; rabit::TrackerPrint(log_stream_.str()); } +#endif } // namespace xgboost diff --git a/src/tree/updater_basemaker-inl.h b/src/tree/updater_basemaker-inl.h index 00009cf55..25faaae4e 100644 --- a/src/tree/updater_basemaker-inl.h +++ b/src/tree/updater_basemaker-inl.h @@ -374,8 +374,10 @@ class BaseMaker: public TreeUpdater { } } else { if (rmax >= next_goal) { - rabit::TrackerPrintf("INFO: rmax=%g, sum_total=%g, next_goal=%g, size=%lu\n", - rmax, sum_total, next_goal, sketch->temp.size); + LOG(TRACKER) << "INFO: rmax=" << rmax + << ", sum_total=" << sum_total + << ", naxt_goal=" << next_goal + << ", size=" << sketch->temp.size; } } rmin = rmax; diff --git a/tests/travis/travis_after_failure.sh b/tests/travis/travis_after_failure.sh index 5eff1239d..553cc979e 100755 --- a/tests/travis/travis_after_failure.sh +++ b/tests/travis/travis_after_failure.sh @@ -2,4 +2,6 @@ if [ ${TASK} == "r_test" ]; then cat xgboost/xgboost.Rcheck/*.log + echo "--------------------------" + cat xgboost/xgboost.Rcheck/*.out fi