Skip to content

Add multithreading support in the electric field calculation#509

Merged
fhagemann merged 2 commits intomainfrom
field_multithreading
Jul 12, 2025
Merged

Add multithreading support in the electric field calculation#509
fhagemann merged 2 commits intomainfrom
field_multithreading

Conversation

@fhagemann
Copy link
Collaborator

Not sure why we never did this before, but the electric field calculation did not support multithreading. Adding it can result in a significant speedup.

Example:

using SolidStateDetectors, Unitful
sim = Simulation(SSD_examples[:CGD])
calculate_electric_potential!(sim, max_tick_distance = 0.05u"mm",
    max_n_iterations = 1, refinement_limits = Float64[])
Simulation: ExampleCuboid
Electric Potential Calculation
Bias voltage: 2000.0 V
Precision: Float32
Device: CPU
Max. CPU Threads: 64
Coordinate system: Cartesian
N Refinements: -> 0
Convergence limit: 1.0e-7  => 0.0002 V
Initial grid size: (374, 366, 370)

Before this PR:

@time calculate_electric_field!(sim)
  6.976945 seconds (16 allocations: 579.623 MiB, 3.73% gc time)

After this PR (using 64 threads)

@time calculate_electric_field!(sim)
  0.304666 seconds (277 allocations: 579.653 MiB, 22.28% gc time)

@oschulz Not sure if the increase in allocations is something to worry about or not, but it is definitely faster now.

@fhagemann fhagemann added the performance Performance improvements label Jul 9, 2025
Comment on lines -160 to -162
if fieldvector_coordinates == :xyz
ef = convert_field_vectors_to_xyz(ef, axφ)
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, I removed fieldvector_coordinates from get_electric_field_from_potential, because I cannot think of a scenario where this should NOT be wanted..

Maybe this function can even be mutating to avoid allocating memory.

@fhagemann fhagemann requested a review from oschulz July 9, 2025 01:19
fhagemann added 2 commits July 8, 2025 18:28
…ial`

I do not see any scenario, in which the resulting electric field should NOT be xyz
@fhagemann fhagemann force-pushed the field_multithreading branch from 03f4cdf to 4e2c897 Compare July 9, 2025 01:28
@fhagemann fhagemann merged commit a05b678 into main Jul 12, 2025
11 checks passed
@fhagemann fhagemann deleted the field_multithreading branch July 12, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants