From b1bffde6c97d2e26a2e8e47e6c04bf90b4c557a8 Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Tue, 26 Aug 2014 09:09:28 -0700 Subject: [PATCH 1/2] fix compile under rtools --- .gitignore | 1 + R-package/src/xgboost_R.cpp | 2 +- src/utils/random.h | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 03dc41255..2620533dc 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ Debug *suo *test* .Rhistory +*.dll diff --git a/R-package/src/xgboost_R.cpp b/R-package/src/xgboost_R.cpp index 58a891004..8bca0de5f 100644 --- a/R-package/src/xgboost_R.cpp +++ b/R-package/src/xgboost_R.cpp @@ -213,7 +213,7 @@ extern "C" { &olen); FILE *fo = utils::FopenCheck(CHAR(asChar(fname)), "w"); for (size_t i = 0; i < olen; ++i) { - fprintf(fo, "booster[%lu]:\n", i); + fprintf(fo, "booster[%u]:\n", static_cast(i)); fprintf(fo, "%s", res[i]); } fclose(fo); diff --git a/src/utils/random.h b/src/utils/random.h index 0233ae496..bf8b04d9d 100644 --- a/src/utils/random.h +++ b/src/utils/random.h @@ -89,16 +89,19 @@ struct Random{ /*! \brief set random number seed */ inline void Seed(unsigned sd) { this->rseed = sd; -#ifdef _MSC_VER +#if defined(_MSC_VER)||defined(_WIN32) srand(rseed); #endif } /*! \brief return a real number uniform in [0,1) */ inline double RandDouble(void) { -#ifndef _MSC_VER - return static_cast(rand_r(&rseed)) / (static_cast(RAND_MAX) + 1.0); + // use rand instead of rand_r in windows, for MSVC it is fine since rand is threadsafe + // For cygwin and mingw, this can slows down parallelism, but rand_r is only used in objective-inl.hpp, won't affect speed in general + // todo, replace with another PRNG +#if defined(_MSC_VER)||defined(_WIN32) + return static_cast(rand()) / (static_cast(RAND_MAX) + 1.0); #else - return static_cast(rand()) / (static_cast(RAND_MAX) + 1.0); + return static_cast(rand_r(&rseed)) / (static_cast(RAND_MAX) + 1.0); #endif } // random number seed From 98e92f1a795d64e54ad3a1ec3065c601b876c043 Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Tue, 26 Aug 2014 09:29:17 -0700 Subject: [PATCH 2/2] more detailed warning --- src/utils/omp.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/omp.h b/src/utils/omp.h index a7f213cc5..8d6531526 100644 --- a/src/utils/omp.h +++ b/src/utils/omp.h @@ -10,7 +10,9 @@ #else #ifndef DISABLE_OPENMP #ifndef _MSC_VER -#warning "OpenMP is not available, compile to single thread code" +#warning "OpenMP is not available, compile to single thread code."\ + "You may want to ungrade your compiler to enable OpenMP support,"\ + "to get benefit of multi-threading." #else // TODO add warning for msvc #endif