Skip to content

OpenMP parallelize grid initialization (set_epsilon)#3166

Draft
Luochenghuang wants to merge 2 commits intoNanoComp:masterfrom
Luochenghuang:openmp-set-epsilon
Draft

OpenMP parallelize grid initialization (set_epsilon)#3166
Luochenghuang wants to merge 2 commits intoNanoComp:masterfrom
Luochenghuang:openmp-set-epsilon

Conversation

@Luochenghuang
Copy link

@Luochenghuang Luochenghuang commented Mar 10, 2026

The grid initialization loop in set_chi1inv iterates over all grid points to compute the inverse permittivity tensor. At high resolutions, this takes awhile on a single core.

Parallelize the loop with OpenMP (PLOOP_OVER_IVECS_C) when the material function is thread-safe (standard C++ geometry objects, not Python callbacks). The trivial[] flags use OpenMP reduction.

A new virtual method material_function::is_thread_safe() returns false by default (safe for Python callbacks). The geom_epsilon subclass overrides it to return true unless MATERIAL_USER materials are present.

Measured speedup: 30.7s -> 3.2s with 22M voxels (9.7x speed using 22 cores). Set OMP_NUM_THREADS to control parallelism.

The grid initialization loop in set_chi1inv iterates over all grid
points to compute the inverse permittivity tensor. At high resolutions
(e.g., 178M points at resolution 200), this takes minutes on a single
core.

Parallelize the loop with OpenMP (PLOOP_OVER_IVECS_C) when the
material function is thread-safe (standard C++ geometry objects, not
Python callbacks). The trivial[] flags use OpenMP reduction.

A new virtual method material_function::is_thread_safe() returns false
by default (safe for Python callbacks). The geom_epsilon subclass
overrides it to return true unless MATERIAL_USER materials are present.

Measured speedup: 30.7s -> 3.2s at resolution 100 (9.7x with 22 cores).
Set OMP_NUM_THREADS to control parallelism.
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.90%. Comparing base (f29a8c7) to head (3a8fd4a).
⚠️ Report is 113 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3166      +/-   ##
==========================================
+ Coverage   73.81%   73.90%   +0.09%     
==========================================
  Files          18       18              
  Lines        5423     5454      +31     
==========================================
+ Hits         4003     4031      +28     
- Misses       1420     1423       +3     

see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
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.

2 participants