diff --git a/doc/modeling.rst b/doc/modeling.rst index f480d1fd..ed12659e 100644 --- a/doc/modeling.rst +++ b/doc/modeling.rst @@ -737,8 +737,7 @@ Automatic computation of actuator length ranges is done at compile time, and the mjModel.actuator_lengthrange of the compiled model. If the model is then saved (either as XML or MJB), the computation does not need to be repeated at the next load. This is important because the computation can slow down the model compiler with large musculo-skeletal models. Indeed we have made the compiler multi-threaded just to speed up this -operation (different actuators are processed in parallel in different threads). Incidentally, this is why the flag -'-pthread' is now needed when linking user code against the MuJoCo library on Linux and macOS. +operation (different actuators are processed in parallel in different threads). Automatic computation relies on modified physics simulation. For each actuator we apply force (negative when computing the minimum, positive when computing the maximum) through the actuator's transmission, advance the simulation in a diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 7ad003ed..f8aa46bc 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -52,25 +53,6 @@ using std::string; using std::vector; } // namespace -// pthread on Linux, std::thread on Mac and Windows -#if defined(__APPLE__) || defined(_WIN32) - #include - using std::thread; - - int getnumproc(void) { - return thread::hardware_concurrency(); - } -#else - #include - #include - - int getnumproc(void) { - return get_nprocs(); - } -#endif - - - //---------------------------------- CONSTRUCTOR AND DESTRUCTOR ------------------------------------ // constructor @@ -1550,7 +1532,7 @@ void mjCModel::LengthRange(mjModel* m, mjData* data) { } // number of threads available, max 16 - const int nthread = mjMIN(16, getnumproc()/2); + const int nthread = mjMIN(16, std::thread::hardware_concurrency()/2); // count actuators that need computation int cnt = 0; @@ -1609,12 +1591,10 @@ void mjCModel::LengthRange(mjModel* m, mjData* data) { err[i][0] = 0; } - // use std::thread -#if defined(_WIN32) || defined(__APPLE__) // launch threads - thread th[16]; + std::thread th[16]; for (int i=0; i