Skip to content

Commit

Permalink
Only distribute biases over threads if they don't need I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomofiorin committed Dec 1, 2023
1 parent 50d3b7d commit 70a726d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/colvarmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,15 @@ int colvarmodule::calc_biases()
}
}

// if SMP support is available, split up the work
if (proxy->check_smp_enabled() == COLVARS_OK) {
bool biases_need_io = false;
for (bi = biases_active()->begin(); bi != biases_active()->end(); bi++) {
if ((bi->replica_share_freq() > 0) && (step_absolute() % bi->replica_share_freq() == 0)) {
biases_need_io = true;
}
}

// If SMP support is available, split up the work (unless biases need to use main thread's memory)
if (proxy->check_smp_enabled() == COLVARS_OK && !biases_need_io) {

if (use_scripted_forces && !scripting_after_biases) {
// calculate biases and scripted forces in parallel
Expand All @@ -1000,10 +1007,12 @@ int colvarmodule::calc_biases()
error_code |= calc_scripted_forces();
}

// Straight loop over biases on a single thread
cvm::increase_depth();
for (bi = biases_active()->begin(); bi != biases_active()->end(); bi++) {
error_code |= (*bi)->update();
if (cvm::get_error()) {
cvm::decrease_depth();
return error_code;
}
}
Expand Down

0 comments on commit 70a726d

Please sign in to comment.