Skip to content

optimise code - #16

Merged
paugier merged 1 commit into
paugier:masterfrom
bolverk:master
Apr 26, 2021
Merged

paugier merged 1 commit into
paugier:masterfrom
bolverk:master

Conversation

@bolverk

@bolverk bolverk commented Apr 23, 2021

Copy link
Copy Markdown
Contributor

No description provided.

@paugier

paugier commented Apr 26, 2021

Copy link
Copy Markdown
Owner

Thanks a lot! On my PC, this (sequential) C++ implementation is a bit faster than the (sequential) Python implementation using Pythran. It's a bit slower than the optimized Julia implementation.

I'm going to mention that in the README. Other optimizations are of course welcome.

@paugier
paugier merged commit d88482b into paugier:master Apr 26, 2021
@paugier

paugier commented Apr 26, 2021

Copy link
Copy Markdown
Owner

See 0555e69 for the exact figures obtained with my PC.

Besides, it is of course important to keep the suboptimal implementation got from nbabel.org !

@isuruf

isuruf commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

Besides, it is of course important to keep the suboptimal implementation got from nbabel.org !

Why is it important? The suboptimal implementation from nbabel.org does twice the work as any other implementation.

@ashwinvis

ashwinvis commented Apr 26, 2021 •

Copy link
Copy Markdown
Contributor

Why is it important? The suboptimal implementation from nbabel.org does twice the work as any other implementation.

@isuruf Because that code's performance was included in the published article (see Citation in the README) and should be kept as is for archival reasons. We do make it clear that the C++ and Fortran implementations were taken as is from nbabel.org. We also mention in the article: "Note that these implementations could have been further optimized, but are representative of code written by many scientists."

@bolverk I do have a question: is this loop criterion correct? Wouldn't it short circuit halfway if sj == si?

for (vector<Star>::iterator sj = s.begin(); sj != si; ++sj) {

@paugier

paugier commented Apr 26, 2021

Copy link
Copy Markdown
Owner

@isuruf One of our points of our note in Nature Astro is that the implementation is more important than the language. This C++ implementation found in nbabel.org has been written by someone knowing C++ and has been used by Zwart (2020). Many real word C++ programs also miss simple algorithmic optimizations.

The goal of our work is not to check how much C++ can be push. Of course, one can write in C++ a very efficient implementation of this problem. It's evident!

We studied a question about Python. "Do we have to avoid this language for ecological reasons?"

@isuruf

isuruf commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

I do have a question: is this loop criterion correct. Wouldn't it short circuit halfway if sj == si?

This is my whole point. In the other languages, the short circuit is there, but in C++ there isn't, which makes the C++ implementation twice as slow.

As you can see in the original nbabel implementation at https://github.com/paugier/nbabel/blob/master/cpp/raw_code.txt#L83, the optimized code path is commented out. So, this optimization was already in the original nbabel implementation.

@ashwinvis

Copy link
Copy Markdown
Contributor

I don't understand and it does not make sense even if I check the equations. The summations should be over all other particles and not all particles before its position in the vector.

@isuruf

isuruf commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

@ashwinvis

This comment has been minimized.

@ashwinvis

Copy link
Copy Markdown
Contributor

The reason is i, j and j, i are updated at the same time

OK I get it now. Thanks :)

@paugier paugier mentioned this pull request Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants