Continue cleanups done in #711#716
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @Yrisch, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on significant code cleanups within the tree data structure and related routines. The primary goal is to remove deprecated and unused parameters, hardcode a constant value where appropriate, and eliminate an unused subroutine. These changes streamline the codebase, improve readability, and reduce unnecessary argument passing, contributing to better maintainability of the simulation's core components.
Highlights
- Deprecated Parameter Removal: The redundant
ndimandndimtreeparameters have been removed from various subroutine signatures and module definitions across the codebase, simplifying function calls and type declarations. This includesmaketree,construct_root_node,push_onto_stack,pop_off_stack,construct_node,getneigh,maketreeglobal, andgetneigh_pos. - Fixed Root Node ID: The
irootnodevariable is now explicitly defined as a parameter with a value of1, removing its dynamic assignment and making its role clearer. - Unused Subroutine Removal: The
update_hmax_remotesubroutine, identified as unused, has been completely removed fromneigh_kdtree.f90, reducing code bloat. - Streamlined Neighbor Search Calls: Calls to
getneigh_posandgetneighacross multiple files (e.g.,H2regions.f90,dens.F90,ptmass.F90,utils_raytracer.f90,analysis_pairing.f90,utils_raytracer_all.f90) have been simplified by removing the now implicitndimargument.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request does a great job of cleaning up the tree routines by removing the deprecated ndim and ndimtree parameters, making irootnode a constant, and removing the unused update_hmax_remote subroutine. The changes are consistent across all modified files and improve the maintainability of the code.
I've added a few suggestions for further improvements:
- A critical fix in
dtype_kdtree.F90to ensure the MPI datatype forkdnodeis correctly defined, which also suggests a more robust way to calculate its size. - A couple of suggestions in
kdtree.F90to use more modern Fortran constructs (array and structure constructors) for more concise and readable code.
Overall, this is a solid set of cleanups. Addressing the critical issue I've pointed out will ensure the correctness of MPI communications.
| integer, parameter :: kdnode_bytes = & | ||
| 8*ndimtree & ! xcen(ndimtree) | ||
| + 8 & ! size | ||
| + 8 & ! hmax | ||
| + 4 & ! leftchild | ||
| + 4 & ! rightchild | ||
| + 4 & ! parent | ||
| 8*3 & ! xcen(3) | ||
| + 8 & ! size | ||
| + 8 & ! hmax | ||
| + 8 & ! mass | ||
| + 4 & ! leftchild | ||
| + 4 & ! rightchild | ||
| + 4 & ! parent | ||
| #ifdef GRAVITY | ||
| + 8 & ! mass | ||
| + 8*6 & ! quads(6) | ||
| + 8*6 & ! quads(6) | ||
| #endif | ||
| + 0 |
There was a problem hiding this comment.
This change correctly moves the mass field to be unconditionally included in kdnode_bytes, which matches the kdnode type definition. However, there are a couple of remaining issues:
- The
idumfield from thekdnodetype is not accounted for in this calculation. - The corresponding MPI type creation in
get_mpitype_of_kdnodehas not been updated. It still only includesmassifGRAVITYis defined, and it also omitsidum. This will lead to incorrect MPI communication whenGRAVITYis not defined.
A more robust way to define kdnode_bytes would be to use the sizeof intrinsic, which would automatically adapt to any changes in the kdnode type definition. This would also make the manual calculation unnecessary.
You would also need to update get_mpitype_of_kdnode to correctly register all fields of kdnode, including mass unconditionally and idum. This is critical for correct MPI behavior.
integer, parameter :: kdnode_bytes = sizeof(kdnode)
| xmini(1) = xminpart | ||
| xmini(2) = yminpart | ||
| xmini(3) = zminpart | ||
| xmaxi(1) = xmaxpart | ||
| xmaxi(2) = ymaxpart | ||
| xmaxi(3) = zmaxpart |
aadaceb to
0b3eade
Compare
Description:
Further cleanups in tree routines. Remove deprecated
ndimandndimtree.irootnodeis now a parameter equal to 1. Remove unusedupdate_hmax_remoteComponents modified:
Type of change:
Testing:
Should be the same in the tests...
Did you run the bots? yes
Did you update relevant documentation in the docs directory? no
Did you add comments such that the purpose of the code is understandable? no
Is there a unit test that could be added for this feature/bug? no