Skip to content

Commit

Permalink
Never use more threads than meshes for multi-threaded compile.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 651728817
Change-Id: Ib607d528c25a10e2cdb8c2b0b0da2189683d2691
  • Loading branch information
yuvaltassa authored and Copybara-Service committed Jul 12, 2024
1 parent 9c9faa0 commit f1aa52a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/user/user_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3322,8 +3322,9 @@ void CompileMesh(mjCMesh* mesh, const mjVFS* vfs, std::exception_ptr& exception,
void mjCModel::CompileMeshes(const mjVFS* vfs) {
std::vector<std::thread> threads;
int nmesh = meshes_.size();
int hardware_threads = std::thread::hardware_concurrency();
int nthread = std::max(1, std::min(kMaxCompilerThreads, hardware_threads / 2));
int hardware_threads = std::thread::hardware_concurrency() / 2;
int maxthread = std::min(nmesh, std::min(kMaxCompilerThreads, hardware_threads));
int nthread = std::max(1, maxthread);

threads.reserve(nthread);

Expand Down Expand Up @@ -3445,7 +3446,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
SetNuser();

// compile meshes (needed for geom compilation)
if (usethread) {
if (usethread && meshes_.size() > 1) {
// multi-threaded mesh compile
CompileMeshes(vfs);
} else {
Expand Down

0 comments on commit f1aa52a

Please sign in to comment.