Skip to content

Conversation

brenjohn
Copy link
Contributor

@brenjohn brenjohn commented Feb 19, 2024

A MethodOrderHilbert class was added which uses a Hilbert curve to order blocks in a simulation.

The class is largely based on the MethodOrderMorton class but with some key logic/functions replaced with Hilbert versions. Namely, the logic for iterating over child blocks in a Morton order was replaced with a Hilbert version (facilitated by a hilbert_children function) and the Index.next method was replaced with MethodOrderHilbert::hilbert_next.

The algorithms for determining the Hilbert order are based on those presented in "Mengjuan Li et al 2023 (Efficient entry point encoding and decoding algorithms on 2D Hilbert space filling curve)" and "Lianyin Jia et al 2022 (Efficient 3D Hilbert curve encoding and decoding algorithms)" which are iterative and use look-up tables rather than recursive. Note, there are typos in the tables presented in these papers, the tables used by the MethodOrderHilbert class should be the correct ones.

@jwise77 jwise77 requested review from jobordner and jwise77 February 23, 2024 17:22
@brenjohn brenjohn changed the title WIP: Hilbert order method for load balancing Hilbert order method for load balancing May 11, 2024
Copy link
Contributor

@jwise77 jwise77 left a comment

Choose a reason for hiding this comment

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

All looks good! It's more complex than what I did with Enzo's Hilbert curve because you considered the octree structure in its calculation. I had one question for my own curiosity about the block weighting as an inline comment and another question about testing. But I can approve it because those are just minor items.

WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# Load Balance
#setup_test_parallel(LoadBalance-1 LoadBalance/morton-1 input/LoadBalance/test_balance-on-bcg.in)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to still test the Morton curve in addition to the Hilbert curve? From the other files, it seems like it's not being removed, so I think it might be a good idea to keep this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test for the Morton method was actually already removed before I added the Hilbert method. My guess is the original test was removed because it was a lengthy cosmological simulation. I added it back in temporarily while I was putting together the Hilbert test and then commented it out. I didn't want to reintroduce a test which was removed and I probably should have removed it entirely instead of commenting it out.


*pindex_(block) = 0;
*pcount_(block) = 0;
*pweight_(block) = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all blocks equally weighted? If so, this is fine. It's just for my curiosity. If we were to have performance timing for each block or some proxy, would this be where the associated weight would be assigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the weighting is the same as in the Morton method as @jobordner said. So all the blocks initially have equal weight and by the end of the method all leaf blocks should have weight 1 and all non-leaf blocks should have a weight = 1 + (the number of its descendant blocks)

@jobordner
Copy link
Contributor

Looks good to me, and works great! (out-performs Morton as expected)

In PR #350 I made some structural changes to ordering (e.g. replaced MethodOrderMorton with MethodOrder), so I'll be merging MethodOrderHilbert into that at some point. Just so you know.

(@jwise77 the weighting is the same as in Morton (the same for all blocks), but the variable "weight" is available so different blocks can be assigned different weights later as needed.)

@jwise77 jwise77 merged commit 420327f into enzo-project:main May 31, 2024
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.

3 participants