Skip to content

Init grid parallelisations - #173

Open
wilfchun wants to merge 1 commit into
developfrom
feature/init_grid-parallelisation
Open

Init grid parallelisations#173
wilfchun wants to merge 1 commit into
developfrom
feature/init_grid-parallelisation

Conversation

@wilfchun

Copy link
Copy Markdown
Collaborator

This pull request significantly improves the parallel performance and thread safety of the nInitGridAndCalcStillWaterLevel function in src/init_grid.cpp by redesigning how accumulators are handled in OpenMP parallel regions. The main change is the introduction of cache-aligned, thread-local accumulators to eliminate false sharing and reduce synchronization overhead, resulting in more efficient and scalable parallel execution.

Parallelization and performance improvements:

  • Introduced a cache-aligned ThreadLocalAccumulators struct and allocated one per thread to prevent false sharing and synchronization bottlenecks during parallel accumulation. This replaces OpenMP reduction clauses with thread-local storage, improving scalability on multi-core systems.
  • Updated the parallel loop to use these thread-local accumulators, ensuring each thread writes to its own cache line and removing the need for reduction clauses. [1] [2]
  • After the parallel region, combined the results from all thread-local accumulators in a sequential pass, which is efficient compared to the parallel workload.

Correctness and code clarity:

  • Changed all per-cell accumulations within the parallel region to use the thread-local accumulators instead of global variables, ensuring thread safety.
  • Added detailed comments explaining the motivation for the changes and the reasoning behind cache alignment and accumulator design. [1] [2]

Minor code cleanup:

  • Fixed a typo in a commented-out variable name (pdRaster allocation).

@wilfchun wilfchun added enhancement New feature or request feature labels Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant