Skip to content

Continue cleanups done in #711#716

Merged
Yrisch merged 4 commits into
danieljprice:masterfrom
Yrisch:cleanup_tree
Sep 12, 2025
Merged

Continue cleanups done in #711#716
Yrisch merged 4 commits into
danieljprice:masterfrom
Yrisch:cleanup_tree

Conversation

@Yrisch

@Yrisch Yrisch commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator

Description:
Further cleanups in tree routines. Remove deprecated ndim and ndimtree. irootnode is now a parameter equal to 1. Remove unused update_hmax_remote

Components modified:

  • Setup (src/setup)
  • Main code (src/main)
  • Moddump utilities (src/utils/moddump)
  • Analysis utilities (src/utils/analysis)
  • Documentation (docs/)

Type of change:

  • Bug fix
  • Physics improvements
  • Better initial conditions
  • Performance improvements
  • Documentation update
  • Other (please describe)
  • cleanups

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 ndim and ndimtree parameters have been removed from various subroutine signatures and module definitions across the codebase, simplifying function calls and type declarations. This includes maketree, construct_root_node, push_onto_stack, pop_off_stack, construct_node, getneigh, maketreeglobal, and getneigh_pos.
  • Fixed Root Node ID: The irootnode variable is now explicitly defined as a parameter with a value of 1, removing its dynamic assignment and making its role clearer.
  • Unused Subroutine Removal: The update_hmax_remote subroutine, identified as unused, has been completely removed from neigh_kdtree.f90, reducing code bloat.
  • Streamlined Neighbor Search Calls: Calls to getneigh_pos and getneigh across 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 implicit ndim argument.
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

  1. 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.F90 to ensure the MPI datatype for kdnode is correctly defined, which also suggests a more robust way to calculate its size.
  • A couple of suggestions in kdtree.F90 to 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.

Comment thread src/main/dtype_kdtree.F90
Comment on lines 21 to 32
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

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:

  1. The idum field from the kdnode type is not accounted for in this calculation.
  2. The corresponding MPI type creation in get_mpitype_of_kdnode has not been updated. It still only includes mass if GRAVITY is defined, and it also omits idum. This will lead to incorrect MPI communication when GRAVITY is 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)

Comment thread src/main/kdtree.F90
Comment on lines +466 to +471
xmini(1) = xminpart
xmini(2) = yminpart
xmini(3) = zminpart
xmaxi(1) = xmaxpart
xmaxi(2) = ymaxpart
xmaxi(3) = zmaxpart

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For conciseness and better readability, you can use array constructors to initialize xmini and xmaxi.

 xmini = (/ xminpart, yminpart, zminpart /)
 xmaxi = (/ xmaxpart, ymaxpart, zmaxpart /)

@Yrisch
Yrisch merged commit beee9f5 into danieljprice:master Sep 12, 2025
694 of 696 checks passed
@Yrisch
Yrisch deleted the cleanup_tree branch September 12, 2025 07:15
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.

1 participant