Loading...
Searching...
No Matches
SpaceFilling.h File Reference

Space-filling curve utilities for cache-optimal atom ordering. More...

#include <algorithm>
#include <cstdint>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  gpr
 Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
namespace  gpr::sfc

Functions

uint32_t gpr::sfc::morton_3d (uint32_t x, uint32_t y, uint32_t z)
 Compute 3D Morton (Z-order) index from integer coordinates.
uint32_t gpr::sfc::morton_to_hilbert_3d (uint32_t morton, uint32_t bits)
 Convert Morton index to Hilbert index using 96-byte LUT.
uint32_t gpr::sfc::hilbert_3d (double x, double y, double z, double min_coord, double scale, uint32_t bits=10)
 Compute 3D Hilbert index from floating-point coordinates.
std::vector< size_t > gpr::sfc::hilbert_permutation (const double *coords, size_t n_atoms, uint32_t bits=10)
 Compute Hilbert-ordered permutation for a set of 3D points.

Variables

constexpr uint8_t gpr::sfc::MORTON_TO_HILBERT_LUT [96]
 96-byte LUT for Morton->Hilbert conversion.

Detailed Description

Space-filling curve utilities for cache-optimal atom ordering.

Implements Morton (Z-order) and Hilbert curve indexing for 3D points. Hilbert curves have better locality than Morton curves at octant boundaries.

Two-step approach: Coordinates -> Morton -> Hilbert

  • Morton via pdep (BMI2) or bit interleaving
  • Morton->Hilbert via 96-byte LUT (2.5x faster than Skilling algorithm)
Note
Cache locality benefit requires PHYSICAL data reordering, not just iteration permutation. Permuting iteration indices while keeping data in original order causes cache misses due to indirection. To get speedup:
  1. Compute hilbert_permutation for atom coordinates
  2. Physically reorder position/type arrays by permutation
  3. Iterate in natural order over reordered data

Reference: https://threadlocalmutex.com/?p=149

Definition in file SpaceFilling.h.