Skip to content
Snippets Groups Projects

When sorting the hydro particles, only recurse if we need to.

Closed Matthieu Schaller requested to merge recurse_less_in_sort into master
4 unresolved threads

@nnrw56 is that what you had in mind?

Merge request reports

Closed by avatar (May 26, 2025 1:38am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
933 933 /* Allocate memory for sorting. */
934 934 cell_malloc_hydro_sorts(c, flags);
935 935
936 /* Does this cell have any progeny? */
936 /* Shall we recurse to a lower level? */
937 int recurse = 0;
937 938 if (c->split) {
939 for (int k = 0; k < 8; k++) {
  • 933 933 /* Allocate memory for sorting. */
    934 934 cell_malloc_hydro_sorts(c, flags);
    935 935
    936 /* Does this cell have any progeny? */
    936 /* Shall we recurse to a lower level? */
    937 int recurse = 0;
    937 938 if (c->split) {
    939 for (int k = 0; k < 8; k++) {
    940
    941 const struct cell *cp = c->progeny[k];
    942
    943 if (cp != NULL && cp->hydro.count > 0) { /* Are there any parts? */
    944
    945 const int do_sub_sort = cell_get_flag(cp, cell_flag_do_hydro_sub_sort);
    946
    947 if (cp->hydro.requires_sorts || /* Do they need sorting? */
  • 937 938 if (c->split) {
    939 for (int k = 0; k < 8; k++) {
    940
    941 const struct cell *cp = c->progeny[k];
    942
    943 if (cp != NULL && cp->hydro.count > 0) { /* Are there any parts? */
    944
    945 const int do_sub_sort = cell_get_flag(cp, cell_flag_do_hydro_sub_sort);
    946
    947 if (cp->hydro.requires_sorts || /* Do they need sorting? */
    948 (cp->hydro.do_sort | flags) || /* Are we forcing a sort? */
    949 do_sub_sort) { /* Do we want a sort at a lower level? */
    950
    951 /* Ok, recurse */
    952 recurse = 1;
    953 break;
  • 935 935
    936 /* Does this cell have any progeny? */
    936 /* Shall we recurse to a lower level? */
    937 int recurse = 0;
    937 938 if (c->split) {
    939 for (int k = 0; k < 8; k++) {
    940
    941 const struct cell *cp = c->progeny[k];
    942
    943 if (cp != NULL && cp->hydro.count > 0) { /* Are there any parts? */
    944
    945 const int do_sub_sort = cell_get_flag(cp, cell_flag_do_hydro_sub_sort);
    946
    947 if (cp->hydro.requires_sorts || /* Do they need sorting? */
    948 (cp->hydro.do_sort | flags) || /* Are we forcing a sort? */
    949 do_sub_sort) { /* Do we want a sort at a lower level? */
  • This looks right in spirit, but I'm not 100% sure about the details, mainly because it's probably been more than a year since I last touched this code...

    IIRC, do_hydro_sub_sort propagates upwards, so if any cell sets it, so do all its parents. Would it be sufficient to just check for that flag? Or is there some use-case I'm missing?

  • Good point. We might be able to get away with reading less. Just need to check that it also works when we have the flags set and not just the cell properties.

  • In other news, on an EAGLE-12 run, this makes absolutely no difference to the number of calls to runner_do_hydro_sort(). We seem to recurse in the exact same way.

  • I can see three options:

    • I am not running a test that is relevant
    • The current infrastructure already prevents the recursion in cells where it is unnecessary
    • My new criterion is not aggressive enough at cutting down the recursion.
  • Please register or sign in to reply
    Loading