Skip to content

First attempt at embarrasingly parallel execution to compute head grids.#140

Draft
dbrakenhoff wants to merge 5 commits into
devfrom
parallel_numba
Draft

First attempt at embarrasingly parallel execution to compute head grids.#140
dbrakenhoff wants to merge 5 commits into
devfrom
parallel_numba

Conversation

@dbrakenhoff

@dbrakenhoff dbrakenhoff commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Early result suggests ~10x speedup on my machine.

Todo

  • Implement to_numba_tuple() for all element families intended for Numba path.
    Add fast potinf and potential kernels for remaining element classes. Missing:
    • CircAreaSink
    • LeakyWall
    • LeakyWallString
    • WellStringBase
  • Support aquifer-region aware evaluation in Numba backend. Reason: model currently
    selects aquifer by location; backend now uses a single aqtuple and ignores aq_id.
  • Preserve Model feature parity in Numba headgrid path. Must include: layers
    selection behavior, steady contribution, and output shape conventions.
  • Add Numba-optimized discharge-vector path: disvec and velocity grids still route
    through Python loops. Write fast parallel implementations for disvec_inf, disvec
    functions.
  • Testing
    • Add correctness tests comparing serial vs Numba-parallel across element mixes.
    • Add regression tests for edge cases that often break Numba kernels. Examples:
      points at well radius, near singular line endpoints, zero/very small times, many
      intervals, mixed g/v/z elements.
  • Documentation
    • Add help for contributors describing how to add new elements to fast numba code.

- add parallel submodule
- define numba tuples containing relevant data for computations for Model, Aquifer and Elements (LineSink and Well) for now. Each class gets to_numba_tuple() method to collect data.
- add integer mappings for elements and boundary conditions for identifying computation path
- gather element data in structured arrays
- write fast versions of potinf and potential
- parallelize on x,y pts
@dbrakenhoff dbrakenhoff self-assigned this Jun 18, 2026
@dbrakenhoff dbrakenhoff added the enhancement New feature or request label Jun 18, 2026
- add parallel submodule
- define numba tuples containing relevant data for computations for Model, Aquifer and Elements (LineSink and Well) for now. Each class gets to_numba_tuple() method to collect data.
- add integer mappings for elements and boundary conditions for identifying computation path
- gather element data in structured arrays
- write fast versions of potinf and potential
- parallelize on x,y pts
@dbrakenhoff

dbrakenhoff commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Parallel example (based on example from Discussion #115)

parallel_example.zip

Note that first run of numba code triggers the compilation step, which means it runs in about ~15s on my machine. The next run takes about ~3s. Normal timflow (using parallel=True, referring to multithreading) is about ~30s.

EDIT: example won't run until #139 is merged into dev and subsequently this branch.

@eriktoller

Copy link
Copy Markdown

Cool work and awesome to see such speed-up already!

Some thoughts:

  • It could be a good idea to skip fastmath=True, at least when still developing the code
  • it would be interesting to look at the difference if you change results_arr=bessellsv2(...) to bessellsv2(restuls_arr,...) and reuse a work array rather than creating a new one per linesink per point (300 linesink for 100 by 100 grid will be a lot of time for memory allocation).
  • it would also be cool if you could time the pre-processing, computations and post-processing of the numba approach to see where the majority of the effort goes into.

I will follow the progress with great interest, great work Davíd 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants