-
Notifications
You must be signed in to change notification settings - Fork 61
Simplify and optimize coordination numbers #909
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
base: master
Are you sure you want to change the base?
Conversation
…ith no changes) In the process, also flip the outdated order of public vs. protected members.
103663c to
6cf14f5
Compare
…gh for given tolerance
|
Side note: an additional simplification I wanted to add would be to change the |
Inlining the functions is required to avoid the performance loss after refactoring.
HanatoK
left a 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.
Looks good to me! Although I need to use inline for compute_pair_coordnum to restore the performance after refactoring.
Thanks! I have been removing |
| if (function_type() != "selfCoordNum") { | ||
|
|
||
| group2 = parse_group(conf, "group2"); | ||
| if (!group2) { | ||
| return error_code | COLVARS_INPUT_ERROR; | ||
| } | ||
|
|
||
| if (int atom_number = cvm::atom_group::overlap(*group1, *group2)) { | ||
| error_code |= cvm::error("Error: group1 and group2 share a common atom (number: " + | ||
| cvm::to_str(atom_number) + ")\n", | ||
| COLVARS_INPUT_ERROR); | ||
| } | ||
|
|
||
| if (function_type() == "coordNum") { | ||
| get_keyval(conf, "group1CenterOnly", b_group1_center_only, group2->b_dummy); | ||
| get_keyval(conf, "group2CenterOnly", b_group2_center_only, group2->b_dummy); | ||
| } | ||
|
|
||
| if (function_type() == "groupCoord") { | ||
| // In groupCoord, these flags are hard-coded | ||
| b_group1_center_only = true; | ||
| b_group2_center_only = true; | ||
| } | ||
|
|
||
| size_t const group1_num_coords = b_group1_center_only ? 1 : group1->size(); | ||
| size_t const group2_num_coords = b_group2_center_only ? 1 : group2->size(); | ||
|
|
||
| num_pairs = group1_num_coords * group2_num_coords; | ||
|
|
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.
Why not using different init() implementations for each derived class of coordnum?
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.
Although there are some sub-cases that differ, the initialization of the cutoffs, exponents and pairlist is shared.
| int pairlist_freq = 100; | ||
|
|
||
| /// Pair list | ||
| std::vector<bool> pairlist; |
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.
When using pairlist, the performance degrades a lot compared to the master branch. I suspect it is because that std::vector<bool> actually use bit fields. @giacomofiorin Have you compared the performance before and after this PR?
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.
Not yet, good to know.
My main goal was to clean up the code and condense code paths, so it should be easy to revert to a C-style array (at the price of higher memory footprint)
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.
It's possible to change to vector<char> but it still doesn't solve the issue of performance loss. You could merge the PR as is if you don't think that the performance loss on CPU is a big issue...
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.
We'll need more precise numbers for relevant use cases, I think.
This PR contains several improvements:
coordnumwith the exception ofh_bondFixes #908