Skip to content
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

Merged
merged 5 commits into from
Dec 4, 2023

Conversation

giacomofiorin
Copy link
Member

@giacomofiorin giacomofiorin commented Dec 1, 2023

Prevents a possible race condition when running multiple-walkers metadynamics with threads. This didn't use to be an issue until recently, when objects do all I/O operations by modifying members of the colvarmodule class.

This fix also removes an earlier restriction on multiple-walkers ABF. No doc changes are needed, since that was not documented anyway.

Possible TODO: check if SMP can be enabled again on NAMD CI jobs, which could have been failing because it's the only engine currently having a CI test for multiple-walkers metadynamics.

@giacomofiorin giacomofiorin added the bugfix To be used only in PRs label Dec 1, 2023
@giacomofiorin
Copy link
Member Author

@jhenin Take a look if this may interfere with you ABF refactoring? Otherwise it should be just a quick merge IMO.

@@ -1466,6 +1466,15 @@ int colvarproxy_namd::compute_volmap(int flags,

#if CMK_SMP && USE_CKLOOP // SMP only

int colvarproxy_namd::check_smp_enabled()
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member

@jhenin jhenin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good: no negative interactions with the ABF changeset.

@jhenin jhenin force-pushed the bias_io_single_thread branch from 2d29389 to 095ecec Compare December 4, 2023 15:46
@giacomofiorin giacomofiorin merged commit 742353d into master Dec 4, 2023
17 checks passed
@giacomofiorin giacomofiorin deleted the bias_io_single_thread branch December 4, 2023 16:26
Copy link
Member

@HanatoK HanatoK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to ask biases themselves if they need I/O instead of checking replica_share_freq() explicitly in colvarmodule.cpp. You could implement virtual bool need_io(step_number step); for each colvarbias class, and then call them in colvarmodule.cpp.

Comment on lines +993 to +995
if (((*bi)->replica_share_freq() > 0) && (step_absolute() % (*bi)->replica_share_freq() == 0)) {
biases_need_io = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is insufficient for metadynamics at least. When newHillFrequency is not the same as replicaUpdateFrequency, biases_need_io would be false. However, in the multi-replica case, metadynamics would still need to open the output stream when projecting a new hill in update_bias() and ((cvm::step_absolute() % new_hill_freq) == 0 (

case multiple_replicas:
add_hill(hill(cvm::step_absolute(), hill_weight*hills_scale,
colvar_values, colvar_sigmas, replica_id));
std::ostream &replica_hills_os =
cvm::proxy->output_stream(replica_hills_file, "replica hills file");
if (replica_hills_os) {
write_hill(replica_hills_os, hills.back());
} else {
return cvm::error("Error: in metadynamics bias \""+this->name+"\""+
((comm != single_replica) ? ", replica \""+replica_id+"\"" : "")+
" while writing hills for the other replicas.\n", COLVARS_FILE_ERROR);
}
), and if metadynamics is not on rank 0 then there would be an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix To be used only in PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants