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

Remove NodeCollection pointer from Node class #2601

Merged

Conversation

med-ayssar
Copy link
Contributor

@med-ayssar med-ayssar commented Feb 1, 2023

The Node class does not need to know about the primitive NodeCollection object it belongs to. Therefore, the NodeManange must keep track of the mapping between a Node instance and the NodeCollection container.

This is a derived requirement for the Vectorization project of the Node class.

@terhorstd terhorstd added T: Enhancement New functionality, model or documentation S: Normal Handle this with default priority I: Internal API Changes were introduced in basic internal workings of the simulator that developers need to know labels Feb 7, 2023
Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

I am seriously concerned about the performance consequences of this change. For spatial connectivity, neurons need to know which node collection they belong to. I expect that this change will make lookup noticeably slower, even though std::lower_bound() has logarithmic complexity. We need to perform systematic benchmarks with spatial models before we proceed to avoid performance regressions on building.

I am also not happy with the mixed-camel-casing and would suggest clear_node_collection_container and similar.

@med-ayssar
Copy link
Contributor Author

I am seriously concerned about the performance consequences of this change. For spatial connectivity, neurons need to know which node collection they belong to. I expect that this change will make lookup noticeably slower, even though std::lower_bound() has logarithmic complexity. We need to perform systematic benchmarks with spatial models before we proceed to avoid performance regressions on building.

I am also not happy with the mixed-camel-casing and would suggest clear_node_collection_container and similar.

The functions using the get_nc in the spatial.cpp have as parameter an array of IDs (i.e, an ArrayDatum of IDs). In order to avoid the possible runtime complexity that I have introduced, we Can group the items in the ArrayDatum by the NodeCollection they belong to, without explicitly searching for the NodeCollection, and then from each group we extract a representative of the group and call the new implemented get_nc function in the NodeManager on the representative item.

@med-ayssar med-ayssar marked this pull request as draft March 10, 2023 07:47
@med-ayssar
Copy link
Contributor Author

med-ayssar commented May 5, 2023

@heplesser, I think last time you said that you might have been overthinking about the performance impact, but those new changes won't have any significant impact on the current performance.

Can we merge this PR, as I need it for the new devices?

@med-ayssar med-ayssar requested a review from heplesser May 5, 2023 14:59
Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

@med-ayssar Please see my comments inline. Also, the compiler seems to miss some things ;). My main concern is still performance. I will see if I can find some good benchmarks.

nestkernel/node_collection.h Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
nestkernel/parameter.cpp Outdated Show resolved Hide resolved
@med-ayssar med-ayssar marked this pull request as ready for review June 13, 2023 12:48
Copy link
Contributor

@jougs jougs left a comment

Choose a reason for hiding this comment

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

Happy if you merge all my suggestions.

nestkernel/node_collection.h Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.cpp Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
nestkernel/node_manager.h Outdated Show resolved Hide resolved
@jougs
Copy link
Contributor

jougs commented Jun 13, 2023

@heplesser: can you please re-review? Thanks!

@heplesser
Copy link
Contributor

@jougs Sorry for the delay. I definitely want to run some benchmarks to check performance effects. I have located suitable benchmarks and will run them within two weeks.

@med-ayssar
Copy link
Contributor Author

@heplesser: I think it can be merged now :D

@heplesser heplesser removed the request for review from nicolossus September 13, 2023 09:48
Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

Looks good now. I performed benchmarks small and large and did not find any noticeable slowdown.

@heplesser heplesser merged commit c04c3dc into nest:master Sep 13, 2023
20 checks passed
Comment on lines +681 to +694
inline size_t
NodeCollection::get_first() const
{
return ( *begin() ).node_id;
}

inline size_t
NodeCollection::get_last() const
{
size_t offset = size() - 1;
return ( *( begin() + offset ) ).node_id;
}


Copy link
Contributor

Choose a reason for hiding this comment

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

I totally realize that it is bad style if

  1. one of the original reviewers (me)
  2. comments on a merged pull request
  3. by a person not working on NEST anymore

🙈

But: couldn't this have been done like this?

Suggested change
inline size_t
NodeCollection::get_first() const
{
return ( *begin() ).node_id;
}
inline size_t
NodeCollection::get_last() const
{
size_t offset = size() - 1;
return ( *( begin() + offset ) ).node_id;
}
inline size_t
NodeCollection::get_first() const
{
return begin()->node_id;
}
inline size_t
NodeCollection::get_last() const
{
return ( end() - 1 )->node_id;
}

Just sayin'...

Copy link
Contributor Author

@med-ayssar med-ayssar Sep 13, 2023

Choose a reason for hiding this comment

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

That was not that simple or better saying, things might get more ugly.

The begin function returns an iterator, and this iterator is a bit complex, as it hides the distinction between the primitive and composite types. Thus, begin()->node_id won't work and also the operator-() is not implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: Internal API Changes were introduced in basic internal workings of the simulator that developers need to know S: Normal Handle this with default priority T: Enhancement New functionality, model or documentation
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants