-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only distribute biases over threads if they don't need I/O #638
Changes from all commits
57e01e0
8e6586d
bc03dda
095ecec
789f22a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -110,9 +110,14 @@ colvarmodule::colvarmodule(colvarproxy *proxy_in) | |||||||||||||||||||||||||
" https://doi.org/10.1080/00268976.2013.813594\n" | ||||||||||||||||||||||||||
"as well as all other papers listed below for individual features used.\n"); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (proxy->smp_enabled() == COLVARS_OK) { | ||||||||||||||||||||||||||
cvm::log("SMP parallelism is enabled (num threads = " + to_str(proxy->smp_num_threads()) + | ||||||||||||||||||||||||||
"); use \"smp off\" to disable if needed.\n"); | ||||||||||||||||||||||||||
if (proxy->check_smp_enabled() == COLVARS_NOT_IMPLEMENTED) { | ||||||||||||||||||||||||||
cvm::log("SMP parallelism is not available in this build.\n"); | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
if (proxy->check_smp_enabled() == COLVARS_OK) { | ||||||||||||||||||||||||||
cvm::log("SMP parallelism is enabled (num threads = " + to_str(proxy->smp_num_threads()) + ").\n"); | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
cvm::log("SMP parallelism is available in this build but not enabled.\n"); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
#if (__cplusplus >= 201103L) | ||||||||||||||||||||||||||
|
@@ -901,7 +906,7 @@ int colvarmodule::calc_colvars() | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// if SMP support is available, split up the work | ||||||||||||||||||||||||||
if (proxy->smp_enabled() == COLVARS_OK) { | ||||||||||||||||||||||||||
if (proxy->check_smp_enabled() == COLVARS_OK) { | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// first, calculate how much work (currently, how many active CVCs) each colvar has | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -983,8 +988,15 @@ int colvarmodule::calc_biases() | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// if SMP support is available, split up the work | ||||||||||||||||||||||||||
if (proxy->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; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+993
to
+995
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is insufficient for metadynamics at least. When colvars/src/colvarbias_meta.cpp Lines 620 to 631 in 632c0db
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this! |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// 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 | ||||||||||||||||||||||||||
|
@@ -1000,10 +1012,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; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
@@ -1955,7 +1969,7 @@ size_t & colvarmodule::depth() | |||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
// NOTE: do not call log() or error() here, to avoid recursion | ||||||||||||||||||||||||||
colvarmodule *cv = cvm::main(); | ||||||||||||||||||||||||||
if (proxy->smp_enabled() == COLVARS_OK) { | ||||||||||||||||||||||||||
if (proxy->check_smp_enabled() == COLVARS_OK) { | ||||||||||||||||||||||||||
int const nt = proxy->smp_num_threads(); | ||||||||||||||||||||||||||
if (int(cv->depth_v.size()) != nt) { | ||||||||||||||||||||||||||
proxy->smp_lock(); | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree with "someone" about this function name. What was the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Did I misinterpret this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder! Back then you suggested replacing the function with two boolean functions. I did just that, except that one of them is not used currently (the one that would indicate if SMP is built into the binary), so I did not add it yet (it would be dead code): we can add it as soon as a use case appears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please do both cases, so that we can use the same runtime to test SMP and non-SMP code path?
Also, your commit will break NAMD compilation for multicore builds (the GH tests pass only because they are building NAMD without SMP)